What does trust proxy do and why does it matter behind nginx?

Express basics and middleware · Experienced

Model answer

Behind a reverse proxy, the connection to Express comes from the proxy, so req.ip, req.protocol and secure cookies can be wrong. app.set('trust proxy', 1) tells Express to trust the first proxy's X-Forwarded-* headers. Set it correctly so rate limiting uses real client IPs, and do not set it to true blindly where clients could fake the header.

Learn this topic

Express Middleware Explained: next(), Logging and express.json() in the course Node.js and Express: Build a Back End API from Scratch.

Sign in to add your own answer.

More questions