Docker n8n with reverse proxy incorrectly includes internal port in webhook endpoints

I have n8n deployed in a Docker container behind a reverse proxy server. The web interface loads correctly through HTTPS, but there’s an issue with webhook URL generation.

The Problem:
When n8n creates webhook URLs, it incorrectly includes the internal container port in the generated links. This causes external services to fail when trying to reach the webhooks.

Expected webhook URL:

https://mysite.com/webhook/bot/abc123

Actual webhook URL generated:

https://mysite.com:5678/webhook/bot/abc123

Current Configuration:

  • n8n container exposed on port 5678
  • Reverse proxy handles SSL termination and forwards requests
  • Web UI accessible via HTTPS works perfectly

Proxy config snippet:

mysite.com {
  reverse_proxy localhost:5678 {
    header_up X-Forwarded-Proto https
    header_up X-Forwarded-Port 443
  }
}

External services like Telegram bots can’t connect to the webhook because of the port number being added. How can I configure n8n to generate clean webhook URLs without the internal port?

This happens because n8n picks up the internal container port from the request headers. Fix it by setting these environment variables in your docker-compose:

N8N_PROTOCOL=https
N8N_HOST=mysite.com
N8N_PORT=443

These variables control how n8n builds all external URLs, not just webhooks. I’ve seen WEBHOOK_URL alone fail to override the port detection completely.

Also check that your reverse proxy strips the port from the Host header before forwarding to n8n - some configs accidentally pass the original port through.

Had this exact headache setting up n8n behind nginx. The problem is n8n builds webhook URLs from the Host header it gets, and your reverse proxy isn’t rewriting it properly. You’re missing the X-Forwarded-Host header - that’s what tells n8n the external hostname. Update your Caddy config like this: mysite.com { reverse_proxy localhost:5678 { header_up X-Forwarded-Proto https header_up X-Forwarded-Port 443 header_up X-Forwarded-Host mysite.com header_up Host mysite.com } } Also set the WEBHOOK_URL environment variable in your n8n container to https://mysite.com. This forces n8n to use that base URL for webhooks instead of guessing from headers. Restart both your reverse proxy and n8n container. The webhook URLs should generate correctly without the port number.

check your n8n env vars - there’s an N8N_HOST setting that could be messsing things up. also, ensure you’re on the latest version since older ones had proxy header issues. sometimes setting WEBHOOK_URL aint enough if other configs clash with it.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.