Q38: How should Express be configured when running behind a Reverse Proxy (Nginx, AWS ALB)?

Difficulty:AdvancedTopic:Deployment

When Express runs behind a reverse proxy (e.g., Nginx, Cloudflare), client connection metadata like original IP addresses and TLS protocols are overwritten by the proxy node.

Enabling app.set('trust proxy', true) instructs Express to read client details from upstream proxy headers like X-Forwarded-For and X-Forwarded-Proto.

Key Takeaways
  • Must enable trust proxy when deploying behind load balancers.
  • Required for rate limiters, geo-IP utilities, and HTTPS secure cookie checks to operate accurately.