【发布时间】:2014-12-21 17:58:44
【问题描述】:
我的 express 服务器在 3000 端口上运行,使用 nginx 作为反向代理。
req.ip 总是返回 127.0.0.1 而 req.ips 返回一个空数组
app.enable('trust proxy');
启用/不启用信任代理,x-forwarded-for 不起作用:
var ip_addr = req.headers['X-FORWARDED-FOR'] || req.connection.remoteAddress;
nginx配置:
服务器 { 听 80; server_name 本地主机; access_log /var/log/nginx/dev_localhost.log; 地点 / { proxy_pass http://localhost:3000; proxy_http_version 1.1; proxy_set_header 升级 $http_upgrade; proxy_set_header 连接“升级”; proxy_set_header 主机 $host; proxy_cache_bypass $http_upgrade; } }如何获取请求客户端的 IP 地址?
【问题讨论】:
-
你的 nginx 配置是什么样的?
-
添加 nginx 配置
标签: node.js express nginx proxy