Point the tunnel at the site's own name instead of No TLS Verify
nginx now carries DOMAIN and www.DOMAIN as aliases on app-network, so cloudflared's origin can be https://www.DOMAIN: it resolves to nginx over the bridge and the Let's Encrypt certificate verifies, with no TLS overrides in the Cloudflare dashboard. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
+20
-16
@@ -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
|
(`CLOUDFLARE_TUNNEL_TOKEN`, editable from the Environment tab); hostnames and
|
||||||
origin settings live in the dashboard.
|
origin settings live in the dashboard.
|
||||||
|
|
||||||
**Origin: `https://nginx:443`, with No TLS Verify.** Cloudflare terminates the
|
**Origin: `https://www.<DOMAIN>`, the site's own name.** Cloudflare
|
||||||
visitor's TLS at its edge, and cloudflared opens a second TLS connection to
|
terminates the visitor's TLS at its edge, and cloudflared opens a second TLS
|
||||||
nginx. That is deliberate. Pointed at `http://nginx:80`, the tunnel would hit
|
connection to nginx. That is deliberate. Pointed at `http://nginx:80`, the
|
||||||
the HTTP→HTTPS redirect and loop. Going to :443 keeps every redirect, security
|
tunnel would hit the HTTP→HTTPS redirect and loop. Going to :443 keeps every
|
||||||
header and the `X-Forwarded-Proto: https` the backend's Secure cookies depend
|
redirect, security header and the `X-Forwarded-Proto: https` the backend's
|
||||||
on, and needs no nginx change. No TLS Verify is needed because cloudflared
|
Secure cookies depend on, and needs no nginx change.
|
||||||
dials the name `nginx`, which the certificate does not cover. The hop never
|
|
||||||
leaves `app-network`.
|
The origin is the public name, not `nginx`, because nginx carries `<DOMAIN>`
|
||||||
|
and `www.<DOMAIN>` 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:
|
Setup, once:
|
||||||
|
|
||||||
@@ -247,11 +253,10 @@ Setup, once:
|
|||||||
3. Put it in `.env` as `CLOUDFLARE_TUNNEL_TOKEN` (or set it from the
|
3. Put it in `.env` as `CLOUDFLARE_TUNNEL_TOKEN` (or set it from the
|
||||||
Environment tab), then `docker compose up -d cloudflared`. The tunnel
|
Environment tab), then `docker compose up -d cloudflared`. The tunnel
|
||||||
shows as Healthy in the dashboard.
|
shows as Healthy in the dashboard.
|
||||||
4. Add a public hostname per name, each with service `HTTPS`, URL
|
4. Add a public hostname per name, each with service `HTTPS` and its own
|
||||||
`nginx:443`, and under Additional application settings → TLS, **No TLS
|
name as the URL, and no other settings:
|
||||||
Verify** on:
|
- `www.<DOMAIN>` → `https://www.<DOMAIN>`: the site.
|
||||||
- `www.<DOMAIN>`: the site.
|
- `<DOMAIN>` → `https://<DOMAIN>`: nginx redirects it to www, and it serves Gitea's registry
|
||||||
- `<DOMAIN>`: nginx redirects it to www, and it serves Gitea's registry
|
|
||||||
at `/v2/`.
|
at `/v2/`.
|
||||||
Creating each hostname replaces the existing A record for that name with
|
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
|
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;
|
- **Certificate renewal.** Over DNS-01 with `CLOUDFLARE_DNS_API_TOKEN` set;
|
||||||
without it certbot falls back to HTTP-01, which needs port 80 forwarded.
|
without it certbot falls back to HTTP-01, which needs port 80 forwarded.
|
||||||
The certificate still matters behind the tunnel: the registry path below
|
The certificate matters behind the tunnel: cloudflared verifies it, as
|
||||||
and any direct LAN access use it. (The tunnel itself would survive an
|
do the registry path below and any direct LAN access. A fresh machine with no
|
||||||
expired one, because of No TLS Verify.) A fresh machine with no
|
|
||||||
certificate at all boots the setup config (§3), which serves nothing over
|
certificate at all boots the setup config (§3), which serves nothing over
|
||||||
443, so the tunnel carries nothing until the first issuance.
|
443, so the tunnel carries nothing until the first issuance.
|
||||||
- **Registry pushes and pulls on the Pi.** Cloudflare caps request bodies at
|
- **Registry pushes and pulls on the Pi.** Cloudflare caps request bodies at
|
||||||
|
|||||||
+15
-4
@@ -118,7 +118,17 @@ services:
|
|||||||
- jobs
|
- jobs
|
||||||
- activity-tracker
|
- activity-tracker
|
||||||
networks:
|
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:
|
ports:
|
||||||
- 80:80
|
- 80:80
|
||||||
- 443:443
|
- 443:443
|
||||||
@@ -160,9 +170,10 @@ services:
|
|||||||
# forwards can be closed. The tunnel is "remotely managed": its public
|
# forwards can be closed. The tunnel is "remotely managed": its public
|
||||||
# hostnames and origin settings live in the Cloudflare dashboard, and this
|
# hostnames and origin settings live in the Cloudflare dashboard, and this
|
||||||
# container only needs the token. The routing set up there (DEPLOYMENT.md,
|
# 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
|
# "Cloudflare Tunnel") is https://www.DOMAIN, which nginx's network aliases
|
||||||
# config, redirects and security headers apply to tunnel traffic exactly as
|
# resolve to nginx itself, so the certificate verifies; nginx's config,
|
||||||
# to direct traffic, and both paths work side by side.
|
# 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
|
# 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
|
# container and no other (set_real_ip_from in nginx.conf.template). It sits
|
||||||
|
|||||||
Reference in New Issue
Block a user