Fixing Telegram Webhooks in n8n (Docker + Caddy) — The Complete Guide With ALL Pain Points
A real‑world troubleshooting walkthrough for anyone self‑hosting n8n with Docker + Caddy + Telegram.
This guide documents every issue you will hit, why it happens, and how to fix it — based on an actual end‑to‑end debugging session.
1. The Core Problem
After installing n8n with Docker Compose, Telegram refuses to accept the webhook URL because n8n keeps generating URLs like:
http://YOUR_SERVER_IP:5678/webhook-test/...
Even after:
-
buying a domain
-
pointing DNS
-
installing Caddy
-
enabling HTTPS
n8n still uses the old IP + port.
This happens because:
n8n does NOT automatically update its base URL.
Docker Compose often hard‑codes old values.
2. Installing Caddy (the easy part)
Install:
sudo apt install caddy
Caddyfile:
yourdomain.com {
reverse_proxy 127.0.0.1:5678
}
Restart:
sudo systemctl restart caddy
Caddy automatically issues HTTPS certificates.
3. The First Major Pain Point: n8n STILL uses the IP
Even with HTTPS working, n8n generates:
http://YOUR_SERVER_IP:5678/webhook-test/...
Telegram rejects it.
Why?
Because n8n is still using the old environment variables from Docker Compose.
4. The .env File Trap
Most tutorials say:
“Edit your
.envfile.”
But in many setups:
Docker Compose does NOT load
.envat all.
So editing .env does nothing.
This is the #1 source of confusion.
5. Finding the Real n8n Folder
To locate your actual Docker Compose folder:
find / -name docker-compose.yml 2>/dev/null
Typical locations:
/opt/n8n
/root/n8n
/home/youruser/n8n
This folder contains:
-
docker-compose.yml -
.env(sometimes unused) -
data/orconfig/
6. The Real Culprit: Hard‑coded IPs in docker-compose.yml
Inside docker-compose.yml, many users find:
environment:
- N8N_HOST=YOUR_SERVER_IP
- N8N_PORT=5678
- N8N_PROTOCOL=http
- WEBHOOK_URL=http://YOUR_SERVER_IP:5678/
This overrides everything else.
This is why n8n refuses to switch to HTTPS.
7. The Second Major Pain Point: Wrong N8N_PORT
Many people try:
N8N_PORT=443
This breaks n8n and causes:
HTTP ERROR 502
Why?
Because:
n8n ALWAYS runs internally on port 5678 inside the container.
Caddy handles HTTPS on port 443.
n8n should NEVER listen on 443.
This is the #2 most common mistake.
8. The Correct docker-compose.yml Environment Block
Here is the correct configuration:
environment:
- N8N_HOST=yourdomain.com
- N8N_PORT=5678
- N8N_PROTOCOL=https
- WEBHOOK_URL=https://yourdomain.com/
- GENERIC_TIMEZONE=America/Los_Angeles
- N8N_SECURE_COOKIE=true
Key points:
-
N8N_PORT stays 5678
-
N8N_PROTOCOL becomes https
-
WEBHOOK_URL uses your domain
-
N8N_SECURE_COOKIE=true is required for HTTPS
9. Restarting n8n Properly
Inside your n8n folder:
docker compose down
docker compose up -d
This reloads the environment variables.
10. Fixing the 502 Error
If you see:
HTTP ERROR 502
It means:
Caddy cannot reach n8n on port 5678.
Fix:
-
Ensure n8n is running on 5678
-
Ensure Caddy proxies to 5678
-
Ensure N8N_PORT=5678
Restart Caddy:
sudo systemctl restart caddy
11. The Final Fix: n8n Webhook URLs
After restarting, n8n should show:
https://yourdomain.com/webhook/...
Telegram Trigger → Connect → SUCCESS.
12. Final Result
Everything works:
-
HTTPS
-
Caddy reverse proxy
-
n8n behind Docker
-
Correct webhook URLs
-
Telegram Trigger connected
-
No more IP‑based URLs
-
No more 502 errors
-
No more “Telegram refused webhook”
This is a production‑grade setup.
13. Summary of All Pain Points (for the community)
Pain Point #1
n8n still used the IP after switching to a domain
Cause: docker-compose.yml hard‑coded old values.
Pain Point #2
Editing .env did nothing
Cause: docker-compose.yml did NOT load .env.
Pain Point #3
Setting N8N_PORT=443 broke everything
Cause: n8n must run on 5678 internally.
Pain Point #4
502 Bad Gateway after editing compose file
Cause: n8n wasn’t reachable on the expected port.
Pain Point #5
Telegram refused webhook URL
Cause: n8n generated HTTP instead of HTTPS.
Pain Point #6
Couldn’t find the n8n folder
Solution:
find / -name docker-compose.yml 2>/dev/null
14. The Final Working Configuration
docker-compose.yml
version: '3.8'
services:
n8n:
image: n8nio/n8n:latest
restart: always
ports:
- "5678:5678"
environment:
- N8N_HOST=yourdomain.com
- N8N_PORT=5678
- N8N_PROTOCOL=https
- WEBHOOK_URL=https://yourdomain.com/
- GENERIC_TIMEZONE=America/Los_Angeles
- N8N_SECURE_COOKIE=true
volumes:
- n8n_data:/home/node/.n8n
volumes:
n8n_data:
Caddyfile
yourdomain.com {
reverse_proxy 127.0.0.1:5678
}
15. The Telegram Error This Guide Fixes
This guide specifically fixes the extremely common Telegram error:
Couldn’t connect with these settings
The resource you are requesting could not be found
This error happens because:
-
Telegram requires HTTPS
-
n8n was generating HTTP webhook URLs
-
n8n was using your server’s IP instead of your domain
-
Docker Compose was hard‑coding old values
-
Caddy was proxying correctly, but n8n wasn’t
After applying this guide:
-
n8n generates HTTPS webhook URLs
-
using your domain
-
Telegram accepts the webhook instantly
This resolves the error permanently.