Not getting remote address while using proxy in socket.io

后端 未结 3 1021
余生分开走
余生分开走 2020-12-28 09:18

In my socket.io code,

socket.sockets.on(\'connection\', function(client){ 
    var ip = client.handshake.address.address;
    ..
}

ip alwa

相关标签:
3条回答
  • 2020-12-28 09:38

    For people who may come from Google, using NGINX: none of these worked for me, I followed the answer in this other question and modified my proxy_pass, to create a new header that node could then use. Don't forget to call sudo systemctl restart nginx after.

    0 讨论(0)
  • 2020-12-28 09:47

    yes, this is working for me.

    client.handshake.headers['x-forwarded-for'] || client.handshake.address.address;
    

    I am properly getting the remote IP address and not 127.0.0.1

    0 讨论(0)
  • 2020-12-28 09:54

    In version > 1.0, the syntax is similar:

    socket.handshake.headers['x-forwarded-for'] || socket.request.connection.remoteAddress;
    
    0 讨论(0)
提交回复
热议问题