Hello everyone,
I’m experiencing a persistent issue while deploying n8n on Railway using the official n8nio/n8n template with workers enabled and a custom domain.
Problem: ERR_ERL_UNEXPECTED_X_FORWARDED_FOR
After setting up the project and successfully pointing my custom domain to Railway, the n8n editor loads but produces the following error continuously in the logs:
ValidationError: The ‘X-Forwarded-For’ header is set but the Express ‘trust proxy’ setting is false (default).
Code: ‘ERR_ERL_UNEXPECTED_X_FORWARDED_FOR’
I have already tried adding the following environment variables:
N8N_TRUST_PROXY=true
N8N_PROXY_HOPS=1
N8N_USE_X_FORWARDED_HOST=true
However, the error persists. I get the exact same error even without linking the custom domain. The problem appears both when using my own domain and when using only the default Railway domain, so the issue does not seem to be related to DNS or domain configuration.
So, appears to be similar to this: N8N Crashes on Startup: trust proxy setting is false despite N8N_TRUST_PROXY env var being set
Since you’ve tried N8N_PROXY_HOPS=1 without seeing any changes, can you share more of your n8n related env variables on Railway? You’ve made sure the application got redeployed after adding/udpating the env variables?
Khem
Thank you for your reply.
Regarding the environment variables: I am using the default ones provided by the official Railway n8n template. These are the ones that come pre-configured out of the box:
-
PORT -
DB_TYPE -
WEBHOOK_URL -
NODE_OPTIONS -
EXECUTIONS_MODE -
DB_POSTGRESDB_HOST -
DB_POSTGRESDB_PORT -
DB_POSTGRESDB_USER -
DB_POSTGRESDB_DATABASE -
DB_POSTGRESDB_PASSWORD -
QUEUE_BULL_REDIS_HOST -
QUEUE_BULL_REDIS_PORT -
QUEUE_BULL_REDIS_PASSWORD -
QUEUE_BULL_REDIS_USERNAME -
QUEUE_BULL_REDIS_DUALSTACK -
ENABLE_ALPINE_PRIVATE_NETWORKING -
OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS -
N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS -
N8N_LISTEN_ADDRESS -
N8N_EDITOR_BASE_URL -
N8N_RUNNERS_ENABLED
Additionally, based on earlier advice, I also tested:
-
N8N_TRUST_PROXY=1 -
N8N_PROXY_HOPS=1 -
N8N_USE_X_FORWARDED_HOST=true
However, the behaviour did not change and the same ERR_ERL_UNEXPECTED_X_FORWARDED_FOR error persists.
About the link you shared:
I checked the thread you mentioned (the one about “trust proxy setting is false despite N8N_TRUST_PROXY being set”), but that discussion is focused on Docker compose deployments, where the user can directly modify the Express server configuration through mounted files or custom Docker images. In my case, I am using the Railway template, which does not provide direct access to the application source code or a Docker compose layer. Therefore, I am unsure whether the same solution can be applied here, as Railway manages the container automatically and does not expose the n8n entrypoint files where the proxy configuration is defined.
For this reason, I would appreciate guidance on how to correctly apply the proxy-related configuration in a Railway environment or whether there is a different recommended approach for hosted deployments.
Thank you again for your time.