Skip to content

[N8N] Fixing Express 'trust proxy' and X-Forwarded-For Error (express-rate-limit)

Published:ย atย 04:12 AM (1 min read)

When deploying n8n with Express on Docker (or any Node.js app behind a proxy), you might encounter the following error:

ValidationError: The 'X-Forwarded-For' header is set but the Express 'trust proxy' setting is false (default). This could indicate a misconfiguration which would prevent express-rate-limit from accurately identifying users.
See https://express-rate-limit.github.io/ERR_ERL_UNEXPECTED_X_FORWARDED_FOR/ for more information

By default, n8n sets N8N_PROXY_HOPS=0, preventing the application from recognizing the X-Forwarded-For header as coming from a trusted proxy.

Solution

Add N8N_PROXY_HOPS to your n8n env or docker-compose.yml:

N8N_PROTOCOL=https
N8N_PORT=5678
# ๐Ÿ‘‡ Add number of reverse proxies n8n is running behind
N8N_PROXY_HOPS=1

express-rate-limit now correctly identifies client IP via X-Forwarded-For header, preventing misidentification and potential errors ๐ŸŽ‰


Previous Post
[LeetCode] 42. Trapping Rain Water
Next Post
[MacOS] How to Resolve 'Can't find the libpq-fe.h header' Error