[英]Not getting remote address while using proxy in socket.io
在我的socket.io代码中,
socket.sockets.on('connection', function(client){
var ip = client.handshake.address.address;
..
}
ip总是返回127.0.0.1,这是因为服务器位于代理后面。 如何正确获取远程地址?
编辑:我正在使用http-proxy
是的,这对我有用。
client.handshake.headers['x-forwarded-for'] || client.handshake.address.address;
我正在获取远程IP地址而不是127.0.0.1
在版本> 1.0中,语法类似:
socket.handshake.headers['x-forwarded-for'] || socket.request.connection.remoteAddress;
对于可能来自Google的人,使用NGINX:这些都不适用于我,我在其他问题中按照答案修改了我的proxy_pass
,以创建一个节点可以使用的新标题。 不要忘记之后调用sudo systemctl restart nginx
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.