elad / node-cluster-socket.io

Writeup on how to make node.js cluster and socket.io play nice
421 stars 63 forks source link

How to use it with nginx reverse proxy? #34

Open rohitkhatri opened 6 years ago

rohitkhatri commented 6 years ago

The connection.remoteAddress is always 127.0.0.1 when using nginx reverse proxy.

cgzegarra commented 6 years ago

I have the same issue here. I read that the only way to fix this is by using a cookie instead of the remoteAddress.

hequanb commented 5 years ago

same issue,I have no idea how to solve this problem..

casperon commented 5 years ago

I think we can forward the client ip address from nginx reverse proxy settings

jmlxxvi commented 5 years ago

You may want to use the following to get the real IP of the client

const ip = req.headers["x-forwarded-for"] || req.connection.remoteAddress;

as the proxy (HAProxy in my case) sends the IP of the client on the header as "x-forwarded-for"

Boohi commented 4 years ago

You may want to use the following to get the real IP of the client

const ip = req.headers["x-forwarded-for"] || req.connection.remoteAddress;

as the proxy (HAProxy in my case) sends the IP of the client on the header as "x-forwarded-for"

Where can we access the request object?