title: Simple Reverse-proxy using nginx
body: <p>I am running a Rails app on <code>http://localhost:3000</code>, which I want to access as <code>http://localhost</code>. 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 <code>http://localhost:3000</code> but I get no response at <code>http://localhost</code>. 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.</p>
  
  <p>Here's a snippet of /etc/nginx/nginx.conf</p>
  
  <pre><code>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/*;
  }
  </code></pre>
  
  <p>The only .conf file in the conf.d directory: /etc/nginx/conf.d/default.conf</p>
  
  <pre><code>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;
      }
  }
  </code></pre>
  
  <p>I followed <a href="http://tweaked.io/guide/nginx-proxying/" rel="nofollow">this page</a> in setting it up. </p>
  
  <p>Also, Content of /etc/nginx/sites-enabled/default, also the only file in sites-enabled directory</p>
  
  <pre><code>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;
      }
  }
  </code></pre>
  
  <p>And when I restart nginx... (the output)</p>
  
  <pre><code>$ 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.
  </code></pre>
  
  <p>And I see this in the log: </p>
  
  <pre><code>2014/10/15 23:28:12 [warn] 5800#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
  </code></pre>