I'n need to get client real IP address in nodeJs, when using nginx proxy server I always get my localhost(127.0.0.1). Can anyone help me to solv this problem? Here is my code
app.set('trust proxy', 'loopback');
app.use(function(req, res, next) {
app.ipInfo = req.headers['x-forwarded-for'] ||
req.connection.remoteAddress ||
req.socket.remoteAddress ||
req.connection.socket.remoteAddress;
next();
});
To configure an original client IP address identification, you can use the NGINX module ngx_http_realip_module. This module allows redefining the value of $remote_addr used by the Wallarm node to get a client IP address.
By using the nginx forward proxy we can masking the location and IP for gaining access to services. Nginx forward proxy will continuing the request on behalf of the client. At the time when the host server will accept the request then only we can see the IP of the nginx proxy server.
Nginx is an open source web server that can also serve as a reverse proxy. Apart from being used to host websites, it's also one of the most widely used reverse proxy and load balancing solutions.
In nginx if you want to pass through the IP address of the remote user to your backend web server you have to set X-Forwarded-For
header to this remote ip, Like this:
proxy_set_header X-Forwarded-For $remote_addr;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With