I am running a Rails app on http://localhost:3000, which I want to access as http://localhost. I am trying to use nginx to do reverse-proxy, and it seems like it should be simple but I haven't gotten it to work. I can access my app at http://localhost:3000 but I get no response at http://localhost. This is my first time toying with nginx so I am not sure what's wrong, where to look for more details. I also looked at 10+ Stack Overflow questions, nginx tutorials and questions but none of them have helped me so far.
Here's a snippet of /etc/nginx/nginx.conf
user www-data;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
# multi_accept on;
}
http {
include /etc/nginx/mime.types;
access_log /var/log/nginx/access.log;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;
gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
The only .conf file in the conf.d directory: /etc/nginx/conf.d/default.conf
upstream backend {
server 127.0.0.1:3000;
}
server {
listen 80;
server_name localhost;
access_log /var/log/nginx/localhost.access.log;
location / {
proxy_pass http://backend;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto http;
proxy_set_header X-NginX-Proxy true;
}
}
I followed this page in setting it up.
Also, Content of /etc/nginx/sites-enabled/default, also the only file in sites-enabled directory
server {
listen 80 default;
server_name localhost;
access_log /var/log/nginx/localhost.access.log;
location / {
root /var/www/nginx-default;
index index.html index.htm;
}
location /doc {
root /usr/share;
autoindex on;
allow 127.0.0.1;
deny all;
}
location /images {
root /usr/share;
autoindex on;
}
}
And when I restart nginx... (the output)
$ sudo service nginx restart
Restarting nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
configuration file /etc/nginx/nginx.conf test is successful
nginx.
And I see this in the log:
2014/10/15 23:28:12 [warn] 5800#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
rails s -p 80. To achieve this you don't need nginx at all... usually, in a dev environment, you don't need an http server like nginx or apache.