0

I understand it is possible to get a visitors IP using code similar to the following:

var ip = req.headers['x-forwarded-for'] || 
     req.connection.remoteAddress || 
     req.socket.remoteAddress ||
     req.connection.socket.remoteAddress;

However when I use this code in my node app (which sits behind a nginx reverse proxy on the same server), I just get the IP 127.0.0.1.

This is my nginx location:

location /myapp {
    proxy_pass http://127.0.0.1:8080;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
}

How can I overcome this problem?

Thanks for your help.

Tom Brock
  • 920
  • 7
  • 29
  • 1
    http://stackoverflow.com/questions/10375659/nginx-proxy-pass-node-ssl – epascarello Mar 15 '16 at 12:09
  • 1
    Possible duplicate of [How to pass the remote IP to a proxied service? - Nginx](http://stackoverflow.com/questions/4880283/how-to-pass-the-remote-ip-to-a-proxied-service-nginx) – Ben Fortune Mar 15 '16 at 12:10
  • 2
    There are also some examples [here](http://stackoverflow.com/questions/5009324/node-js-nginx-what-now/5015178#5015178) – Ben Fortune Mar 15 '16 at 12:13

0 Answers0