I have a problem with nginx and node, because when I want to get the ip of the user with node, it works fine in my localhost (don't use nginx), but it doesn't work on my server as it should. I researched and see that node no - the first one that gets ip is nginx and after nginx sends a request to node. then the ip that node receives is my server, not the user's ip address. look at the nignx configuration server:
location / {
proxy_pass https://fotogena.co:8000; <-nginx send req to node
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_connect_timeout 1000;
proxy_send_timeout 1500;
proxy_read_timeout 2000;
}
I use "req.connection.remoteAddress" to find out the ip of the user, and the console will show me the ip of my server. Does anyone know how to solve this problem?
thanks: D
----------- 2016-04-20 --------
I can solve the problem with this line in setting up the nginx file
proxy_set_header X-Real-IP $remote_addr;
and node.js
req.headers['x-forwarded-for']
source