title: How to set and configure node.js with express to nginx reverse proxy on centos 6.4 virtualbox client?
body: <p>I am creating a development VM on my Windows 8.1 system using VirtualBox 4.3.4 and installed CentOS 6.4 as my VMServer. I installed NginX and Node.js with no problems. With little knowledge of administration I deleted the contents of <code>/etc/sysconfig/iptables</code> allowing all connections for development purpose only as of the moment (which will be changed later).</p>
  <p>NginX is working fine, on my Windows host, and pointing the browser to <code>http://192.168.1.20</code> shows that the &quot;Welcome to nginx on EPEL!&quot; page is working.</p>
  <p>Verifying that my node.js app is working correctly, I created a node app on my VMServer by running</p>
  <pre><code>[~]# express node_nginx_practice
  [~]# cd node_nginx_practice &amp;&amp; npm install
  [~]# node app
  </code></pre>
  <p>Then, on my Windows host, point the URL to <code>http://192.168.1.20:3000</code>, the &quot;Express default&quot; page is running with no problem.</p>
  <p><strong>The question is how could I set and configure node app to serve on nginx reverse-proxy?</strong></p>
  <p>example: <code>http://192.168.1.20 //will point to Express default page</code></p>
  <p>I tried setting my nginx config in <code>/etc/nginx/nginx.conf</code> by following some tutorials on the web with no luck url still points to the NginX &quot;Welcome to nginx on EPEL!&quot; page.</p>
  <p>Here's my <code>nginx.conf</code></p>
  <pre><code># For more information on configuration, see:
  #   * Official English Documentation: http://nginx.org/en/docs/
  #   * Official Russian Documentation: http://nginx.org/ru/docs/
  
  user              nginx;
  worker_processes  1;
  
  error_log  /var/log/nginx/error.log;
  #error_log  /var/log/nginx/error.log  notice;
  #error_log  /var/log/nginx/error.log  info;
  
  pid        /var/run/nginx.pid;
  
  
  events {
      worker_connections  1024;
  }
  
  
  http {
      include       /etc/nginx/mime.types;
      default_type  application/octet-stream;
  
      log_format  main  '$remote_addr - $remote_user [$time_local] &quot;$request&quot; '
                        '$status $body_bytes_sent &quot;$http_referer&quot; '
                        '&quot;$http_user_agent&quot; &quot;$http_x_forwarded_for&quot;';
  
      access_log  /var/log/nginx/access.log  main;
  
      sendfile        on;
      #tcp_nopush     on;
  
      #keepalive_timeout  0;
      keepalive_timeout  65;
  
      #gzip  on;
  
      # Load config files from the /etc/nginx/conf.d directory
      # The default server is in conf.d/default.conf
      include /etc/nginx/conf.d/*.conf;
  
      server {
          listen 80;
          server_name localhost;
          location / {
              proxy_set_header X-Real-IP $remote_addr;
              proxy_set_header X-Forwarder-For $proxy_add_x_forwarded_for;
              proxy_set_header Host $http_host;
              proxy_set_header X-NginX-Proxy true;
              proxy_pass http://127.0.0.1:3000;
              proxy_redirect off;
          }
      }
  }
  </code></pre>
  <p>I know I am missing something. Could someone point me to right direction?</p>
  <h2><strong>EDIT ANSWER:</strong></h2>
  <p>Here's what i did to solve the issue in step by step! (Thanks to &quot;C Blanchard&quot;)</p>
  <p>edit the default NginX config file:</p>
  <pre><code>[~]# vim /etc/nginx/conf.d/default.conf
  </code></pre>
  <p>and comment everything that is inside by prepending &quot;#&quot; to all of the lines.</p>
  <p>restart NginX</p>
  <pre><code>[~]# /etc/init.d/nginx restart
  </code></pre>
  <p>Now the url points to the express page.</p>
  <p><strong>EDIT UPDATE: Better solution.</strong></p>
  <p>Open /etc/nginx/conf.d/default.conf find the location block and comment it by appending &quot;#&quot;, and change specify the right location block pointing to node.js app. See code example below.</p>
  <pre><code>... 
  
  #access_log  logs/host.access.log  main;
  
  # Comment this block
  #location / {
  #    root   /usr/share/nginx/html;
  #    index  index.html index.htm;
  #}
  
  # This is the changed location block
  location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarder-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-NginX-Proxy true;
      proxy_pass http://127.0.0.1:3000;
      proxy_redirect off;
  }
  
  error_page  404              /404.html;
  location = /404.html {
      root   /usr/share/nginx/html;
  }
  
  ...
  </code></pre>
  <p>Now I remove the server block that I specified in /etc/nginx/nginx.conf</p>
  <pre><code># Load config files from the /etc/nginx/conf.d directory
  # The default server is in conf.d/default.conf
  include /etc/nginx/conf.d/*.conf;
  
  # Remove from here
  server {
      listen 80;
      server_name localhost;
      location / {
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarder-For $proxy_add_x_forwarded_for;
          proxy_set_header Host $http_host;
          proxy_set_header X-NginX-Proxy true;
          proxy_pass http://127.0.0.1:3000;
          proxy_redirect off;
      }
  }
  # Remove till here
  </code></pre>
  <p>}</p>