How to forward request IP from NGINX to node.js application? How to forward request IP from NGINX to node.js application? express express

How to forward request IP from NGINX to node.js application?


Express.js official site has this guide. Instructions:

  1. app.set('trust proxy', true) in js.
  2. proxy_set_header X-Forwarded-For $remote_addr in nginx.conf
  3. You can now read-off the client IP address from req.ip property


This solves it taking into consideration above NGINX config.

var ip = req.headers['x-real-ip'] || req.connection.remoteAddress;