Complete guide to setting up Cloudflare tunnels with fixed domains.
Simple Cloudflare tunnel with dynamic domain
Suppose that we want to publish localhost:3000
cloudflared tunnel --url http://localhost:3000Cloudflare tunnel with fixed domain
1. Authenticate
cloudflared loginThen select domain from the browser prompt.
2. Create tunnel
cloudflared tunnel create <tunnel name>tunnel name: The name of the service or group of services on your local machine
Example: foo-services = a tunnel for multiple projects
Example output:
cloudflared tunnel create foo-services
# Tunnel credentials written to ~/.cloudflared/61dbf6c3-a7e3-4d1b-80e4-15a1d90fd374.json.# cloudflared chose this file based on where your origin certificate was found. Keep this file secret.# To revoke these credentials, delete the tunnel.# Created tunnel foo-services with id 61dbf6c3-a7e3-4d1b-80e4-15a1d90fd374<tunnel uuid>.json → UUID required for config.yml
3. Update config.yml
Create/Update config.yml file
# use zed editorzed ~/.cloudflared/config.ymlAdd content to file:
Simple configuration (single domain):
url: http://localhost:3000tunnel: <tunnel uuid>credentials-file: ~/.cloudflared/<tunnel uuid>.jsonAdvanced configuration (multiple domains):
tunnel: 61dbf6c3-a7e3-4d1b-80e4-15a1d90fd374credentials-file: ~/.cloudflared/61dbf6c3-a7e3-4d1b-80e4-15a1d90fd374.jsoningress: - hostname: sub-1.altrf.dev service: http://localhost:8100 - hostname: sub-2.altrf.dev service: http://localhost:4321 - service: http_status:404Tunnel id 61dbf6c3... has multiple (domain → local service) mapping
⚠️ Important: The last row of ingress must be service: http_status:404
In the example file above, we map sub-1 public domain to django 8100 and sub-2 public domain to astro 4321.
4. Create domain mapping
cloudflared tunnel route dns <tunnel uuid or name> <host name>You can create multiple domain mappings:
cloudflared tunnel route dns 61db... sub-1.yourdomain.comcloudflared tunnel route dns 61db... sub-2.yourdomain.com5. Start tunnel
cloudflared tunnel run <tunnel uuid/name>