title: NodeJS working behind Nginx
body: <p>I have in the same server NodeJS and Nginx running at a time. Nginx takes the requests from "www.example.com" and i want NodeJS to take requests from "api.example.com". I almost got it, i configured Nginx to forward the requests from "api.example.com" to NodeJS (localhost:3000) and certainly it works, except for the requests arrive to NodeJS without any information.</p>
  
  <p>For example, I'm using PassportJS to develop all the logic behind NodeJS. I have something like this:</p>
  
  <pre><code>app.post('/room/create', function(req, res) { console.log(req); } );
  </code></pre>
  
  <p>And "req", the var who is supposed to store all the information from the request is empty when i access by "api.ismuser.com". But, if i use the public IP:PORT to get NodeJS, it works.</p>
  
  <p>I'm just guessing this is due to Nginx, who is working like a reverse proxy for NodeJS.</p>
  
  <p>I don't know if putting Nginx in front of NodeJS is well done, but it was the only way i found to get working www.ismuser.com and api.ismuser.com with the same public IP.</p>
  
  <p>What can i do?</p>
  
  <hr>
  
  <p>UPDATED</p>
  
  <p>Nginx.conf:</p>
  
  <pre><code>http {
      passenger_root /home/ubuntu/.rvm/gems/ruby-2.0.0-p195@ism_r3/gems/passenger-4.0.5;
      passenger_ruby /home/ubuntu/.rvm/wrappers/ruby-2.0.0-p195@ism_r3/ruby;
  
      include       mime.types;
      default_type  application/octet-stream;
      sendfile        on;
      keepalive_timeout  65;
  
      upstream backend {
          server 127.0.0.1:3000;
      }
  
      server {
          listen 80;
          server_name api.example.com;
  
          location / {
                  proxy_set_header X-Real-IP $remote_addr;
                  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                  proxy_set_header Host $http_host;
                  proxy_set_header X-NginX-Proxy true;
                  proxy_pass http://backend/;
                  proxy_redirect off;
          }
      }
  
      server {
        listen 80;
        server_name www.example.com;
        root /home/ubuntu/ismapi/ism/public;   # &lt;--- be sure to point to 'public'!
        passenger_enabled on;
      }
  }
  </code></pre>