ngingx proxy express get real ip
To get the real IP address of a client making a request through an NGINX proxy to an Express server, you can follow the steps below:
Configure NGINX to Forward Real IP: In the NGINX configuration, set the
proxy_set_header
directive to forward the real IP address of the client. Use the$remote_addr
variable to capture the original client IP.Set Express to Trust NGINX Proxy: In the Express server setup, use the
app.set('trust proxy', true)
method to make it trust the headers set by the NGINX proxy server.Access Real IP in Express: Once the Express server trusts the NGINX proxy, it can access the real IP address of the client from the
X-Forwarded-For
orX-Real-IP
headers, which were set by NGINX.
By following these steps, the Express server can accurately retrieve the real IP address of the client even when requests are made through an NGINX proxy.