通过nginx做了反向代理后,在node中拿到的ip都是
127.0.0.1
,解决这个问题需要配置nginx以下信息;
配置前,获取到错误的ip
image.png配置后,获取到正确的ip
image.png方法:
需要添加以下配置项:
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
案例:
location /hope {
proxy_pass http://127.0.0.1:7001;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
网友评论