簡體   English   中英

在socket.io中使用代理時沒有獲取遠程地址

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM