user644745 user644745 - 2 years ago 155
Node.js Question

Not getting remote address while using proxy in

In my code,

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

ip always returns and this is because the server sits behind a proxy.
How do I get remote address properly ?

Edit: I am using http-proxy

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download