A Cloudflare Tunnel connects the server to Cloudflare from the inside. Cloudflare serves HTTPS. The server opens no ports. Use it when ports 80 and 443 are not free, or when the server has no public IP address.
A tunnel needs a domain in your Cloudflare account. With --no-domain or --ip, the script does not offer the tunnel.
Limits
- Cloudflare stops a request after 100 seconds. A webhook that waits longer for its run gets an error.
- Cloudflare stops uploads over 100 MB (on the Free and Pro plans).
- Live event streams work through the tunnel.
Make the tunnel
- Open the Cloudflare dashboard.
- Open Zero Trust > Networks > Tunnels.
- Click Create a tunnel. Select the type Cloudflared.
- Give the tunnel a name, for example
zerodot. - Cloudflare shows an install command. Copy the token: the long text after
--token.
Keep the token secret. Anyone with the token can run the tunnel.
Automatic
sudo ZERODOT_TUNNEL_TOKEN='<token>' bash install.sh zerodot.example.com --proxy cloudflared
Without ZERODOT_TUNNEL_TOKEN, the script asks for the token. It checks that the text is a tunnel token.
What the script does depends on the mode:
| Case | What the script does | Service for the public hostname |
|---|---|---|
| Docker mode | Adds a cloudflared container to the install. Saves the token in .env (ZERODOT_TUNNEL_TOKEN). |
http://proxy:3000 |
| Native mode | Installs the cloudflared package and service (cloudflared service install <token>). |
http://127.0.0.1:<web port> |
| cloudflared runs on the server already | Installs nothing. Does not ask for a token. | http://127.0.0.1:<port> |
At the end, the script prints the hostname and the service. Then do the last step in Cloudflare:
- Open Zero Trust > Networks > Tunnels.
- Open your tunnel. Open Public hostname. Click Add a public hostname.
- Set Subdomain and Domain, for example
zerodotandexample.com. - Set Service to the value that the script printed. Example: type
HTTP, URLproxy:3000. - Save. Cloudflare makes the DNS record.
The address works after this step.
In native mode, the tunnel has one upstream: the web port. The web app sends the API paths to the API app itself (ZERODOT_API_PORT on the web service). Thus the tunnel needs no path rules.
Manual
Docker mode
Add the token to
.envin the install folder:echo "ZERODOT_TUNNEL_TOKEN=<token>" | sudo tee -a /var/www/zerodot/.envAdd this service to
docker-compose.override.yml:services: cloudflared: image: cloudflare/cloudflared:latest command: [tunnel, --no-autoupdate, run] environment: TUNNEL_TOKEN: ${ZERODOT_TUNNEL_TOKEN:?set ZERODOT_TUNNEL_TOKEN} restart: unless-stopped depends_on: [proxy]Start it:
cd /var/www/zerodot docker compose up -dIn Cloudflare, add the public hostname with the service
http://proxy:3000.
The cloudflared container is in the Docker network of the install. It reaches the Caddy container of the install by the name proxy.
Native mode
Install cloudflared.
Debian and Ubuntu:
sudo install -d -m 0755 /usr/share/keyrings curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg | sudo tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null echo 'deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared any main' | sudo tee /etc/apt/sources.list.d/cloudflared.list sudo apt update sudo apt install -y cloudflaredFedora, RHEL, Rocky and Alma:
sudo curl -fsSL https://pkg.cloudflare.com/cloudflared.repo -o /etc/yum.repos.d/cloudflared.repo sudo dnf install -y cloudflaredArch:
sudo pacman -S --needed cloudflaredInstall the service with the token:
sudo cloudflared service install <token>In Cloudflare, add the public hostname with the service
http://127.0.0.1:3000. Use the web port of your install (WEB_PORTin.zerodot-install).
cloudflared runs on the server already
Do not install a second cloudflared. Add a public hostname to the tunnel that exists:
- Docker mode: service
http://127.0.0.1:3000(the port indocker-compose.override.yml). - Native mode: service
http://127.0.0.1:<web port>.
If that cloudflared runs in a container, 127.0.0.1 is the container, not the server. Connect the container to the network of the install and use http://proxy:3000. See A proxy in Docker.
Firewall
A tunnel needs no open port. The script does not open ports 80 and 443 with a tunnel. You can keep them closed.