Servers · 6 min read

Publishing a site with Cloudflare Tunnel

This website lives on a server at home, on a private IP. Cloudflare Tunnel is how it reaches the internet without opening any ports on my router.

Why not just port-forward?

How it works

A small program, cloudflared, runs on the server and opens an outbound connection to Cloudflare. When someone visits the domain, Cloudflare sends the request back down that connection to the local web server. Nothing inbound is ever opened.

Visitor → Cloudflare edge (TLS) → tunnel → cloudflared → localhost:8080

Setup (config-file method)

  1. Install cloudflared from Cloudflare's official package repository.
  2. Log in and pick the domain: cloudflared tunnel login
  3. Create the tunnel: cloudflared tunnel create portfolio
  4. Point the domain at it: cloudflared tunnel route dns portfolio example.com
  5. Write the config file shown below, then run it as a service.
# /etc/cloudflared/config.yml
tunnel: <TUNNEL-ID>
credentials-file: /etc/cloudflared/<TUNNEL-ID>.json

ingress:
  - hostname: example.com
    service: http://localhost:8080
  - service: http_status:404   # catch-all: anything else gets 404

You can also create the tunnel from the Cloudflare Zero Trust dashboard. It gives you a single install command with a token, and you manage the routes in the browser instead of a file.

Security checklist

Anything the tunnel can reach, the internet can reach. Keep the ingress list short.
← Back to all notes