Fixing Telegram Webhooks in n8n (Docker + Caddy) — The Complete Guide With ALL Pain Points


:rocket: 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.


:puzzle_piece: 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.


:puzzle_piece: 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.


:puzzle_piece: 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.


:puzzle_piece: 4. The .env File Trap

Most tutorials say:

“Edit your .env file.”

But in many setups:

Docker Compose does NOT load .env at all.

So editing .env does nothing.

This is the #1 source of confusion.


:puzzle_piece: 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/ or config/


:puzzle_piece: 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.


:puzzle_piece: 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.


:puzzle_piece: 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


:puzzle_piece: 9. Restarting n8n Properly

Inside your n8n folder:

docker compose down
docker compose up -d

This reloads the environment variables.


:puzzle_piece: 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


:puzzle_piece: 11. The Final Fix: n8n Webhook URLs

After restarting, n8n should show:

https://yourdomain.com/webhook/...

Telegram Trigger → Connect → SUCCESS.


:tada: 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.


:firecracker: 13. Summary of All Pain Points (for the community)

:cross_mark: Pain Point #1

n8n still used the IP after switching to a domain
Cause: docker-compose.yml hard‑coded old values.

:cross_mark: Pain Point #2

Editing .env did nothing
Cause: docker-compose.yml did NOT load .env.

:cross_mark: Pain Point #3

Setting N8N_PORT=443 broke everything
Cause: n8n must run on 5678 internally.

:cross_mark: Pain Point #4

502 Bad Gateway after editing compose file
Cause: n8n wasn’t reachable on the expected port.

:cross_mark: Pain Point #5

Telegram refused webhook URL
Cause: n8n generated HTTP instead of HTTPS.

:cross_mark: Pain Point #6

Couldn’t find the n8n folder
Solution:

find / -name docker-compose.yml 2>/dev/null


:green_circle: 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
}


:stop_sign: 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.


3 Likes

Great guide!! Addresses most of errors encountered while setting up Telegram on n8n.

Using ngrok would bypass the need to buy a domain.

CloudFlare quick tunnel is another viable alternative

3 Likes

Thank you @kjooleng that’s important to know to avoid buying a domain.

1 Like

Hi @NE_automation, welcome, and thanks for sharing this.

I really like tutorials that reflect real experience rather than just theory. When people build or solve problems themselves and share the pain points, the guide becomes much more valuable for the community.

This is a very practical and useful topic; thanks again for putting it together.

2 Likes

Thank you @Haian_Abou-Karam That was my experience and I am glad you find it valuable.

2 Likes