I have n8n set up in a Docker container on my virtual server, and I’ve configured Caddy as a reverse proxy to serve it securely over HTTPS. The configuration works well because I can reach the n8n interface using https://example.com without any issues. However, I am facing a problem where n8n appends the default internal port number (5678) to the webhook URLs. This leads to failures when external services like Telegram try to access the webhook endpoints due to a mismatch in port numbers.
For instance, instead of generating a simple URL like:
https://example.com/webhook/telegram/xyz
n8n outputs:
https://example.com:5678/webhook/telegram/xyz
This causes issues, as external services cannot connect to the specified port.
Here’s how my configuration looks:
- Running n8n inside Docker on port 5678
- Caddy reverse proxy managing HTTPS and forwarding to localhost:5678
- Accessing n8n via https://example.com works perfectly in the browser
n8n.example.com {
reverse_proxy localhost:5678 {
header_up X-Forwarded-Proto https;
header_up X-Forwarded-Port 443;
}
}
What steps can I take to ensure n8n generates the correct webhook URLs without including the port number?
check if you’ve got N8N_EDITOR_BASE_URL set - it sometimes messes with webhook generation. also add header_up X-Forwarded-Host {host} to your Caddy config since n8n needs that header to figure out the right external url. i’ve seen cases where just setting the webhook_url env var wasn’t enough without proper host forwarding.
Had the exact same problem with n8n behind a reverse proxy. n8n can’t figure out the external URL on its own, so you need to set WEBHOOK_URL=https://example.com in your Docker environment variables. This forces n8n to use the right external URL for webhooks instead of defaulting to whatever internal port it’s running on. I’d also throw in N8N_HOST with your domain name just to keep things consistent. Restart the container after adding these and your webhook URLs should generate properly without that annoying port suffix.
n8n isn’t detecting the external URL properly when it’s behind a reverse proxy. You need to set the N8N_WEBHOOK_URL environment variable in your Docker setup. Add N8N_WEBHOOK_URL=https://example.com to your docker-compose file or Docker run command. Also make sure your Caddy config forwards the Host header by adding header_up Host {host} to your reverse proxy block. This combo fixes the issue - n8n will generate webhook URLs with the correct external domain instead of showing the internal port number. n8n needs these environment variables and forwarded headers to build proper URLs for external services.