diff --git a/DEPLOYMENT.md b/DEPLOYMENT.md index e22e448..5dc39f3 100644 --- a/DEPLOYMENT.md +++ b/DEPLOYMENT.md @@ -230,14 +230,20 @@ _remotely managed_ tunnel: the only thing in this repo is the token (`CLOUDFLARE_TUNNEL_TOKEN`, editable from the Environment tab); hostnames and origin settings live in the dashboard. -**Origin: `https://nginx:443`, with No TLS Verify.** Cloudflare terminates the -visitor's TLS at its edge, and cloudflared opens a second TLS connection to -nginx. That is deliberate. Pointed at `http://nginx:80`, the tunnel would hit -the HTTP→HTTPS redirect and loop. Going to :443 keeps every redirect, security -header and the `X-Forwarded-Proto: https` the backend's Secure cookies depend -on, and needs no nginx change. No TLS Verify is needed because cloudflared -dials the name `nginx`, which the certificate does not cover. The hop never -leaves `app-network`. +**Origin: `https://www.`, the site's own name.** Cloudflare +terminates the visitor's TLS at its edge, and cloudflared opens a second TLS +connection to nginx. That is deliberate. Pointed at `http://nginx:80`, the +tunnel would hit the HTTP→HTTPS redirect and loop. Going to :443 keeps every +redirect, security header and the `X-Forwarded-Proto: https` the backend's +Secure cookies depend on, and needs no nginx change. + +The origin is the public name, not `nginx`, because nginx carries `` +and `www.` as network aliases on `app-network` (`docker-compose.yml`). +Inside the network those names resolve to the nginx container, so the hop +never leaves the Pi, and cloudflared verifies the Let's Encrypt certificate +against a name it covers. `https://nginx` would fail that check and need No +TLS Verify. The flip side: **an expired certificate now takes the tunnel down +with a 502**, which is why renewal over DNS-01 (step 5) matters. Setup, once: @@ -247,11 +253,10 @@ Setup, once: 3. Put it in `.env` as `CLOUDFLARE_TUNNEL_TOKEN` (or set it from the Environment tab), then `docker compose up -d cloudflared`. The tunnel shows as Healthy in the dashboard. -4. Add a public hostname per name, each with service `HTTPS`, URL - `nginx:443`, and under Additional application settings → TLS, **No TLS - Verify** on: - - `www.`: the site. - - ``: nginx redirects it to www, and it serves Gitea's registry +4. Add a public hostname per name, each with service `HTTPS` and its own + name as the URL, and no other settings: + - `www.` → `https://www.`: the site. + - `` → `https://`: nginx redirects it to www, and it serves Gitea's registry at `/v2/`. Creating each hostname replaces the existing A record for that name with a CNAME to the tunnel. **That is the cutover**: until then the tunnel @@ -268,9 +273,8 @@ Setup, once: - **Certificate renewal.** Over DNS-01 with `CLOUDFLARE_DNS_API_TOKEN` set; without it certbot falls back to HTTP-01, which needs port 80 forwarded. - The certificate still matters behind the tunnel: the registry path below - and any direct LAN access use it. (The tunnel itself would survive an - expired one, because of No TLS Verify.) A fresh machine with no + The certificate matters behind the tunnel: cloudflared verifies it, as + do the registry path below and any direct LAN access. A fresh machine with no certificate at all boots the setup config (§3), which serves nothing over 443, so the tunnel carries nothing until the first issuance. - **Registry pushes and pulls on the Pi.** Cloudflare caps request bodies at diff --git a/docker-compose.yml b/docker-compose.yml index e1d0b85..a221639 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -118,7 +118,17 @@ services: - jobs - activity-tracker networks: - - app-network + app-network: + # The site's public names, resolving to this container for everything + # on app-network. They exist for cloudflared: its tunnel origin is + # https://www.DOMAIN, which lands here over the bridge with a name the + # Let's Encrypt certificate actually covers, so the tunnel verifies + # TLS with no extra dashboard settings (`https://nginx` would fail the + # name check). Any other container that calls the public site now + # reaches nginx directly instead of hairpinning through the internet. + aliases: + - ${DOMAIN} + - www.${DOMAIN} ports: - 80:80 - 443:443 @@ -160,9 +170,10 @@ services: # forwards can be closed. The tunnel is "remotely managed": its public # hostnames and origin settings live in the Cloudflare dashboard, and this # container only needs the token. The routing set up there (DEPLOYMENT.md, - # "Cloudflare Tunnel") is https://nginx:443 with No TLS Verify, so nginx's - # config, redirects and security headers apply to tunnel traffic exactly as - # to direct traffic, and both paths work side by side. + # "Cloudflare Tunnel") is https://www.DOMAIN, which nginx's network aliases + # resolve to nginx itself, so the certificate verifies; nginx's config, + # redirects and security headers apply to tunnel traffic exactly as to + # direct traffic, and both paths work side by side. # # Fixed address so nginx can trust the CF-Connecting-IP header from this # container and no other (set_real_ip_from in nginx.conf.template). It sits