2.2 KiB
2.2 KiB
Caddy Dual TLS + Cloudflare Tunnel Setup
This architecture provides End-to-End Dual TLS Encryption:
- Edge TLS (Cloudflare Edge Certificate): Cloudflare terminates HTTPS for public visitors on the internet.
- Origin TLS (Let's Encrypt / ACME Certificate): Caddy automatically requests and renews valid SSL/TLS certificates using the Cloudflare DNS-01 ACME challenge plugin.
- Tunnel Transport: Cloudflare Tunnel (
cloudflared) connects to Caddy overHTTPS://caddy:443with strict origin TLS verification.
📁 File Structure
Dockerfile: Builds Caddy withgithub.com/caddy-dns/cloudflareusingxcaddy.docker-compose.yml: Runscaddyandcloudflaredon the shared Docker bridge network.Caddyfile: Configuressynotrip.kucial.com&blog.kucial.comwith DNS-01 TLS challenge..env: StoresCLOUDFLARE_API_TOKENandCLOUDFLARE_TUNNEL_TOKEN.data/: Persistent volume storing Caddy's Let's Encrypt certificates.
🚀 Setup & Cloudflare Dashboard Configuration
1. In .env
CLOUDFLARE_API_TOKEN: Token withZone:DNS:Editpermission (allows Caddy to complete the DNS-01 challenge).CLOUDFLARE_TUNNEL_TOKEN: Token from Cloudflare Zero Trust Tunnels.
2. In Cloudflare Zero Trust Dashboard (Public Hostnames)
Add your subdomains under your Tunnel's Public Hostnames:
| Public Hostname | Service Type | URL | Origin Server Name (under Additional Settings -> TLS) |
|---|---|---|---|
synotrip.kucial.com |
HTTPS |
caddy:443 |
synotrip.kucial.com |
blog.kucial.com |
HTTPS |
caddy:443 |
blog.kucial.com |
Note
Setting Origin Server Name tells
cloudflaredwhich SNI hostname to send to Caddy during the TLS handshake, allowing Caddy to serve the matching Let's Encrypt certificate.
3. Start Services
docker compose up -d --build
4. Zero-Downtime Reload
docker compose exec caddy caddy reload --config /etc/caddy/Caddyfile