-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat: Add Cloudflare Tunnel integration #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This commit introduces Cloudflare Tunnel (cloudflared) integration to allow you to easily expose your self-hosted services to the internet.
Key changes:
- Added a `cloudflared` service to `docker-compose.yml`. This service uses the `cloudflare/cloudflared:latest` image and is configured via a `CLOUDFLARED_TOKEN` environment variable. It depends on the Caddy service.
- Verified that the existing `Caddyfile` configuration is suitable for acting as an origin for Cloudflare Tunnel. Caddy will continue to manage local SSL and route traffic to backend applications as configured by its hostname variables (e.g., `N8N_HOSTNAME`, `WEBUI_HOSTNAME`).
- Updated `README.md` with a new "Cloudflare Tunnel Integration" section. This section explains:
- How to obtain and set the `CLOUDFLARED_TOKEN`.
- How to configure the Cloudflare Tunnel in the Cloudflare dashboard to point to the Caddy service (typically `https://host.docker.internal:443` or `http://host.docker.internal:<caddy_http_port>`).
- That the relevant Caddy hostname variable (e.g., `N8N_HOSTNAME`) must be set to the public domain being tunneled.
- Added `CLOUDFLARED_TOKEN` to `.env.example` with an explanatory comment.
This integration provides a secure and convenient way for you to access your services remotely without needing to configure complex network settings or expose ports directly.
|
Thanks, looks good, I will take a look as soon as this is done: #72 |
|
Hi everyone, I ran into an issue where this commit setup fails in the newest "main" branch. Caddy can't get an SSL certificate from Let's Encrypt, leading to errors. After some infinite loops, I got it working perfectly. This guide explains how to properly configure Caddy to work behind a Cloudflare Tunnel using a free Cloudflare Origin Certificate. The Problem: Why It FailsThe core issue is how Caddy and Cloudflare Tunnels interact with SSL validation:
The Solution: Use a Cloudflare Origin CertificateThe correct approach is to let Cloudflare handle the public-facing SSL and use a special, free Origin Certificate to secure the connection between Cloudflare's edge and your local Caddy server. Here's the step-by-step guide: Step 1: Create a Cloudflare Origin Certificate
Step 2: Configure Your ProjectFirst, place your new certificate files in a directory that Docker can access. A good structure is: Next, ensure your In services:
caddy:
# ... your other caddy settings
volumes:
# ... other volumes
- ./caddy/certs:/etc/caddy/certs:ro # <-- Add this lineStep 3: Update Your CaddyfileNow, tell Caddy to stop trying to use Let's Encrypt and instead use the files you provided for your public-facing services. In # Example for one service. Repeat for all public services.
{$N8N_HOSTNAME} {
# This tells Caddy to use the mounted Cloudflare Origin Certificate
# instead of trying to fetch one from Let's Encrypt.
tls /etc/caddy/certs/origin.pem /etc/caddy/certs/origin.key
# Reverse proxy to your internal service
reverse_proxy n8n:5678
}Step 4: Configure the Cloudflare TunnelThis is the final, crucial piece. You need to tell your tunnel how to correctly connect to Caddy over HTTPS.
After these steps, your setup will be secure and fully functional. The browser sees a valid Cloudflare certificate, and the connection from Cloudflare to your local machine is encrypted and verified using the Origin Certificate. I hope this helps others who want to run this amazing stack locally without exposing ports or paying for a cloud server. A big thank you to @coleam00 for the incredible package! This "local-first" approach is powerful. Adding tunnel support makes it accessible to even more people, especially those behind restrictive networks without port forwarding. Great work. Also thank you @thesteganos for the original code, it took me down the correct rabbit hole. |
This commit introduces Cloudflare Tunnel (cloudflared) integration to allow you to easily expose your self-hosted services to the internet.
Key changes:
cloudflaredservice todocker-compose.yml. This service uses thecloudflare/cloudflared:latestimage and is configured via aCLOUDFLARED_TOKENenvironment variable. It depends on the Caddy service.Caddyfileconfiguration is suitable for acting as an origin for Cloudflare Tunnel. Caddy will continue to manage local SSL and route traffic to backend applications as configured by its hostname variables (e.g.,N8N_HOSTNAME,WEBUI_HOSTNAME).README.mdwith a new "Cloudflare Tunnel Integration" section. This section explains:CLOUDFLARED_TOKEN.https://host.docker.internal:443orhttp://host.docker.internal:<caddy_http_port>).N8N_HOSTNAME) must be set to the public domain being tunneled.CLOUDFLARED_TOKENto.env.examplewith an explanatory comment.This integration provides a secure and convenient way for you to access your services remotely without needing to configure complex network settings or expose ports directly.