2

In node.js + socket.io I use this code to get user's IP address:

var clientIP = socket.handshake.headers['x-forwarded-for'] || socket.handshake.address.address;

But the result is wrong. I console.log'd these values and got the following results:

socket.handshake.address.address is obviously internal IP (127.x.x.x)

x-forwarded-for is one of the cloud9's proxies (107.23.232.64, 54.236.78.114, 107.23.123.140).

So apparently double proxying is used and one of the proxy layers does not provie 'x-forwarded-for' header, right? Is getting real IP of the user absolutely impossible with cloud9? It is essential for my project.

4

1 回答 1

2

Cloud9 确实使用两层代理来访问在工作区中运行的应用程序。第一个代理检查访问权限,第二个代理将请求通过隧道传送到工作区。第二个代理由我们的基础设施提供商 OpenShift 托管,它覆盖了x-forwarded-for第一个代理设置的标头。不幸的是,我们目前无法解决此问题。正如评论中提到的,尽量避免依赖遥控器的 IP。

于 2013-10-03T09:09:42.520 回答