Serve the site through a Cloudflare tunnel
Test and deploy / test (push) Successful in 2m9s
Test and deploy / deploy (push) Successful in 1m45s

A cloudflared container dials out to Cloudflare and forwards the site's
hostnames to nginx on :443, so the router's 80/443 forwards can close.
nginx takes the visitor's address from CF-Connecting-IP, trusted only from
cloudflared's fixed IP, so rate limits stay per visitor.

certbot can now validate over DNS-01 through the Cloudflare API when
CLOUDFLARE_DNS_API_TOKEN is set, so renewal needs no inbound port; without
it, it falls back to the webroot as before. DEPLOYMENT.md covers setup and
what stays off the tunnel: registry traffic on the Pi (pin the apex to
127.0.0.1 to dodge the 100 MB body cap), Gitea SSH and the radio harbor
(Tailscale).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-15 14:03:10 +01:00
co-authored by Claude Opus 5.5
parent 3da49f4b24
commit 602aa522d6
7 changed files with 278 additions and 72 deletions
+21 -4
View File
@@ -101,10 +101,10 @@ http {
# really concurrency protection, not abuse
# protection.
#
# NOTE: the key is the direct client IP. Since nginx is the edge here (no
# CDN or upstream proxy in front), that is correct. If anything is ever put
# in front, these zones must switch to a trusted X-Forwarded-For or every
# visitor will share one bucket.
# NOTE: the key is the client IP, which is only right because of the
# real-IP lines below. Traffic through the Cloudflare tunnel reaches nginx
# from the cloudflared container, so without them every tunnel visitor
# would share that one address and one bucket.
#
# login, api, upload and hotel_search are USED from
# nginx_routes.conf.template, which dev includes too — so
@@ -116,6 +116,23 @@ http {
limit_req_zone $binary_remote_addr zone=upload:10m rate=30r/m;
limit_req_zone $binary_remote_addr zone=hotel_search:10m rate=3r/m;
# ---- Real client IP behind the Cloudflare tunnel -------------------------
# For connections from the cloudflared container, and only those, replace
# $remote_addr with the visitor's address from Cloudflare's
# CF-Connecting-IP header. Everything downstream then just works: the
# rate-limit keys above, the access log, and the X-Real-IP /
# X-Forwarded-For headers sent upstream.
#
# The trust is pinned to cloudflared's fixed address (ipv4_address in
# docker-compose.yml; change both together), NOT the whole app-network
# subnet. Direct visitors on the forwarded 80/443 can arrive from the
# bridge gateway, 172.28.0.1, when docker's userland proxy handles the
# connection, so trusting the subnet would let anyone pick their own IP,
# and so their own rate-limit bucket, by sending the header themselves.
# Production only: dev has no tunnel.
set_real_ip_from 172.28.255.250;
real_ip_header CF-Connecting-IP;
log_format compact
'$remote_addr "$request" $status rt=$request_time';