node.js - Express - req.ip returns 127.0.0.1 -
i have express server running on port 3000 nginx reverse proxy.
req.ip returns 127.0.0.1 , req.ips returns empty array
app.enable('trust proxy');
with/without enabling trust proxy, x-forwarded-for doesn't work:
var ip_addr = req.headers['x-forwarded-for'] || req.connection.remoteaddress;
nginx configuration:
server { hear 80; server_name localhost; access_log /var/log/nginx/dev_localhost.log; location / { proxy_pass http://localhost:3000; 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 ip address of requesting client?
you need pass appropriate x-forwarded-for
header upstream. add together these lines upstream config:
node.js express nginx proxy
No comments:
Post a Comment