Files
ansible/roles/docker/templates/Caddyfile.j2
T
PhilandClaude Opus 5.5 9696c0e441 caddy: reload instead of restart, validate before deploy, HTTP catch-all, header timeout, body limits; dns: drop stale records
- Caddyfile moves to config/ (directory mount) so 'caddy reload' sees the
  new file; the handler reloads gracefully instead of restarting
- template validate: runs 'caddy validate' with the image Caddy uses
- http:// catch-all aborts plain-HTTP requests for unknown hosts / bare IP;
  known hosts keep the automatic HTTPS redirect (tested)
- read_header timeout 10s (default 1 min)
- body_limit snippet: 1MB static sites, tinyauth, repaircafe; 10MB Pocket ID,
  Changedetection, ByteStash, Gotify, iGotify; 20MB Baikal
- dns: remove grist, habits, office, podcasts, pdftools (nothing serves them)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 13:13:16 -07:00

367 lines
11 KiB
Caddyfile

{
servers {
timeouts {
# Clients get 10 s to send request headers (default 1 min), so
# slow-header connections can't pile up. Bodies (uploads) and
# responses are not limited.
read_header 10s
}
}
{% if caddy_custom %}
# Plugins come from the custom image (repo phil/caddy-custom).
order crowdsec first
order appsec after crowdsec
crowdsec {
api_url http://crowdsec:8080
api_key {$CROWDSEC_API_KEY}
ticker_interval 15s
appsec_url http://crowdsec:7422
# Inspect at most 1 MiB of a body (uploads, registry pushes).
appsec_max_body_bytes 1048576
# CrowdSec being down must not take every site down.
appsec_fail_open
}
{% endif %}
}
# Plain-HTTP requests for hostnames we don't serve, or for the bare IP:
# close the connection instead of redirecting. Known hosts still get
# Caddy's automatic HTTPS redirect (inserted before this catch-all), and
# ACME HTTP challenges are answered before routing. Unknown names over
# HTTPS already fail the TLS handshake (no certificate).
http:// {
abort
}
# Tell browsers to always use HTTPS for each site for a year. No
# includeSubDomains, so hosts not served here are unaffected.
# defer: replace any HSTS header an app sends itself, so there's only one.
(hsts) {
header {
Strict-Transport-Security "max-age=31536000"
defer
}
}
# JSON access log shared by every site, in the caddy_data volume
# (/data/logs). Read by humans and, later, CrowdSec. Caddy already redacts
# Cookie/Authorization headers; the filter also masks ?token= (Gotify clients
# put their app token in the query string).
(logging) {
log {
output file /data/logs/access.log {
roll_size 50MiB
roll_keep 10
roll_keep_for 720h
}
format filter {
request>uri query {
replace token REDACTED
replace access_token REDACTED
replace code REDACTED
}
request>headers>X-Gotify-Key replace REDACTED
request>headers>X-Api-Key replace REDACTED
}
}
}
# Headers for proxied apps. "?" only sets a header the app didn't send, so
# apps with their own (stricter) values keep them. Server/X-Powered-By are
# dropped so responses don't advertise software versions.
(security_headers) {
header {
?X-Content-Type-Options nosniff
?Referrer-Policy strict-origin-when-cross-origin
-Server
-X-Powered-By
}
}
# Refuse to be framed by other sites (clickjacking). Not for apps that are
# meant to be embedded elsewhere (HeyForm forms).
(no_framing) {
header ?X-Frame-Options SAMEORIGIN
}
# Static sites: everything above plus a CSP. No default-src so existing
# scripts, styles and images keep working; it blocks plugins, <base>
# hijacking, framing and forms posting off-site.
(static_site) {
import logging
import hsts
import security_headers
import protect
import body_limit 1MB
header {
Content-Security-Policy "base-uri 'self'; object-src 'none'; frame-ancestors 'self'; form-action 'self'"
X-Frame-Options SAMEORIGIN
Permissions-Policy "camera=(), microphone=(), geolocation=(), payment=(), usb=()"
}
}
# Require a Pocket ID login (via Tinyauth) for requests matching the named
# matcher passed as the argument, e.g. "import sso @admin". Tinyauth also
# checks group membership per app (tinyauth-env.j2).
(sso) {
forward_auth {args[0]} tinyauth:3000 {
uri /api/auth/caddy
copy_headers Remote-User Remote-Email Remote-Groups
}
}
# CrowdSec, imported by every site (via site/static_site). Empty unless the
# custom image is on and the stage is enabled (caddy_crowdsec_enforce,
# caddy_appsec). AppSec skips bulk binary traffic: registry and git pushes.
(protect) {
{% if caddy_custom and caddy_crowdsec_enforce %}
crowdsec
{% endif %}
{% if caddy_custom and caddy_appsec %}
@appsec not path /v2/* /api/packages/* */git-upload-pack */git-receive-pack */info/refs
appsec @appsec
{% endif %}
}
# Per-IP limit on login/token POSTs: import ratelimit_login <zone> <paths...>
# Zone names must be unique per site. Our own networks are exempt.
(ratelimit_login) {
{% if caddy_custom and caddy_ratelimit %}
rate_limit {
zone {args[0]} {
match {
method POST
path {args[1:]}
not remote_ip {{ crowdsec_allowlist | join(' ') }}
}
key {client_ip}
events 10
window 1m
}
log_key
}
{% endif %}
}
# Largest request body a site accepts: import body_limit <size>. Only for
# sites that never take big uploads; larger requests get 413.
(body_limit) {
request_body {
max_size {args[0]}
}
}
# Every proxied site: log, HSTS and the shared headers.
(site) {
import logging
import hsts
import security_headers
import protect
}
{{ subdomains.pocketid }} {
import site
import no_framing
import body_limit 10MB
import ratelimit_login pocketid_login /api/webauthn/login/* /api/one-time-access-token* /api/one-time-access-email*
reverse_proxy pocket-id:1411
}
{{ subdomains.tinyauth }} {
import site
import no_framing
import body_limit 1MB
import ratelimit_login tinyauth_login /api/oauth/*
reverse_proxy tinyauth:3000
}
paper.thesatelliteoflove.com {
import site
import no_framing
import ratelimit_login paperless_login /accounts/login/ /api/token/
reverse_proxy paperlessngx-webserver-1:8000
}
cal.thesatelliteoflove.com {
import site
import no_framing
import body_limit 20MB
redir /.well-known/caldav /dav.php 302
redir /.well-known/carddav /dav.php 302
# Web admin needs Pocket ID; CalDAV/CardDAV (/dav.php) stays as is.
@admin path /admin /admin/*
import sso @admin
reverse_proxy baikal-baikal-1:80
}
{{ subdomains.books }} {
import site
import no_framing
import ratelimit_login kavita_login /api/Account/login /api/Account/forgot-password /api/Plugin/authenticate
reverse_proxy kavita:5000
}
audio.thesatelliteoflove.com {
import site
import no_framing
import ratelimit_login abs_login /login /auth/refresh
reverse_proxy audiobookshelf-audiobookshelf-1:80
}
loclog.thesatelliteoflove.com {
import site
import no_framing
import ratelimit_login dawarich_login /users/sign_in
reverse_proxy dawarich_app:3000
}
watcher.thesatelliteoflove.com {
import site
import no_framing
import body_limit 10MB
import ratelimit_login cd_login /login
# UI needs Pocket ID; the API (own key) stays reachable for scripts.
@ui not path /api/*
import sso @ui
reverse_proxy changedetection:5000
}
snippets.thesatelliteoflove.com {
import site
import no_framing
import body_limit 10MB
import ratelimit_login bytestash_login /api/auth/login /api/auth/register
reverse_proxy bytestash:5000
}
git.thesatelliteoflove.com {
import site
import no_framing
import ratelimit_login gitea_login /user/login /user/sign_up /user/forgot_password /user/two_factor* /login/oauth/access_token
reverse_proxy gitea:3000
}
thesatelliteoflove.com {
import static_site
# WebFinger for phil@ serves two readers: the fediverse (GoToSocial's account
# domain is this apex) and Tailscale, which finds the tailnet's login
# provider through the OpenID issuer link.
# Answered for every query: Tailscale's lookup doesn't always send
# resource=acct:phil@..., and phil is the only account here anyway.
@webfinger_phil path /.well-known/webfinger
route {
header @webfinger_phil Content-Type application/jrd+json
header @webfinger_phil Access-Control-Allow-Origin *
respond @webfinger_phil `{"subject":"acct:phil@{{ primary_domain }}","aliases":["https://{{ subdomains.social }}/users/phil","https://{{ subdomains.social }}/@phil"],"links":[{"rel":"http://openid.net/specs/connect/1.0/issuer","href":"https://{{ subdomains.pocketid }}"},{"rel":"http://webfinger.net/rel/profile-page","type":"text/html","href":"https://{{ subdomains.social }}/@phil"},{"rel":"self","type":"application/activity+json","href":"https://{{ subdomains.social }}/users/phil"}]}` 200
# Other fediverse discovery goes to GoToSocial.
redir /.well-known/host-meta* https://{{ subdomains.social }}{uri} 301
redir /.well-known/nodeinfo https://{{ subdomains.social }}{uri} 301
}
root * /srv/tsol
file_server
}
bookmarks.thesatelliteoflove.com {
import site
import no_framing
import ratelimit_login karakeep_login /api/auth/callback/credentials /api/auth/signin/*
reverse_proxy hoarder-web-1:3000
}
social.thesatelliteoflove.com {
import site
import no_framing
import ratelimit_login gts_login /auth/sign_in /oauth/token /auth/2fa*
reverse_proxy gotosocial:8080
}
models.thesatelliteoflove.com {
import site
import no_framing
import ratelimit_login manyfold_login /users/sign_in
reverse_proxy manyfold-app-1:3214
}
gotify.thesatelliteoflove.com {
import site
import no_framing
import body_limit 10MB
import ratelimit_login gotify_login /client /user
reverse_proxy gotify:80
}
gotify-assistant.thesatelliteoflove.com {
import site
import no_framing
import body_limit 10MB
reverse_proxy igotify-assistant:8080
}
pdg.thesatelliteoflove.com {
import static_site
root * /srv/pdg
# "{path}/" keeps the /dir -> /dir/ redirect; "{path}/index.html" is
# needed for "/" itself, which "{path}/" never matches in Caddy 2.11.
try_files {path} {path}.html {path}/ {path}/index.html =404
file_server
encode gzip
handle_errors {
rewrite * /{err.status_code}.html
file_server
}
}
starpunk.thesatelliteoflove.com {
import site
import no_framing
import ratelimit_login starpunk_login /auth/login /auth/authorize /auth/token
# MCP endpoint and its OAuth protected resource metadata (StarPunk v2.15.0)
@mcp path /mcp /mcp/* /.well-known/oauth-protected-resource /.well-known/oauth-protected-resource/*
handle @mcp {
reverse_proxy starpunk-mcp:8001
}
handle {
reverse_proxy starpunk:8000
}
}
repair.nerder.land {
import static_site
root * /srv/repair
file_server
}
nerder.land {
import static_site
root * /srv/nerderland
file_server
}
forms.nerder.land {
import site
reverse_proxy heyform-heyform-1:9157
}
listmonk.nerder.land {
import site
import no_framing
import ratelimit_login listmonk_login /admin/login /subscription/form /api/public/subscription
reverse_proxy listmonk:9000
}
repaircafe.nerder.land {
import site
import body_limit 1MB
redir /volunteer-signup https://listmonk.nerder.land/subscription/form 301
}
gokapi.thesatelliteoflove.com {
import site
import no_framing
import ratelimit_login gokapi_login /login
reverse_proxy gokapi:53842
}