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.