Reputation: 85
the scenario is that I have created a instance on aws and on that clone my rails project and run using rails s command on localhost:3000. and the server is running using PUMA.
now I want to see my app running on public DNS that is http://ec2-13-56-156-255.us-west-1.compute.amazonaws.com/
for that I have install the nginx web server and I am able to see the default index page of nginx but when I am making change to see my app in nginx.conf file it is giving me 403 error. changes are as follows.
file path: /etc/nginx/nginx.conf
user ec2-user;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local]
"$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
index index.html index.htm;
upstream app {
server 127.0.0.1:3000;
#server unix:///path_to_my_app/tmp/sockets/puma.sock fail_timeout=0;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name 13.56.156.255;
root /home/ec2-user/Projects/aqua_web_v1.0;
#root /usr/share/nginx/html;
#location / {
#}
location @app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
Upvotes: 0
Views: 1445
Reputation: 1504
you need to create server block config file by copying over the default file:
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/example.com
now open that file with sudo
previlege
sudo nano /etc/nginx/sites-available/example.com
and then add your host name to:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/example.com;
index index.html index.htm index.nginx-debian.html;
server_name example.com www.example.com;
location / {
try_files $uri $uri/ =404;
}
}
for more details checkout this digitalocean guide: https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-16-04
Upvotes: 0