I’m using n8n in a Docker container on a virtual server, employing Caddy as a reverse proxy to serve it securely via HTTPS. While I can successfully access the n8n interface through my domain, there’s an issue with the webhook URLs generated by n8n.
It appends the port number (5678) to webhook URLs, which leads to connection issues for external services like Telegram since they fail to reach the endpoints with that port included.
The expected format for the webhook URL is: https://example.com/webhook/telegram/xyz
However, n8n generates: https://example.com:5678/webhook/telegram/xyz
Here’s my current setup:
n8n running in Docker on port 5678
Caddy proxy managing HTTPS and forwarding to localhost:5678
This is probably an n8n URL detection issue. Check if you’ve set N8N_PROTOCOL=https in your Docker environment - without it, n8n defaults to http and screws up URL generation. Also verify Caddy’s passing the Host header correctly. Sometimes the original host header gets lost during proxying and confuses n8n about which domain to use. I had the same setup and fixed it by explicitly setting WEBHOOK_TUNNEL_URL=https://example.com as an environment variable. This tells n8n exactly what base URL to use for webhook generation, ignoring internal port config entirely.
make sure you set the WEBHOOK_URL in n8n to just https://example.com or it might keep adding that port. it doesn’t recognize the Caddy stuff automatically, so you gotta tell it directly.
Same problem here when I set up n8n behind a reverse proxy. n8n doesn’t detect the proxy config properly and just uses its internal port for webhooks. You need to set N8N_HOST and N8N_PORT environment variables in your Docker container. Add N8N_HOST=example.com and N8N_PORT=443 to your docker-compose file or run command. This tells n8n which external host and port to use for webhook URLs. Also make sure your Caddy config has the X-Forwarded-Host header with the others you’ve got. n8n sometimes needs that specific header to understand the proxy setup. Restart your n8n container after these changes and the webhook URLs should generate correctly without the port suffix.