Notes
Two config files in one container: what falls between _headers and nginx.conf
Headers come from the build, nginx.conf is hand-maintained, and a single converter sits between them - every real bug I hit fell into that seam.
A static site in a container usually carries two configuration files with completely different provenance. public/_headers is read by the build: Astro rewrites the CSP hashes for inline scripts into it, then scripts/headers-to-nginx.mjs converts it into an nginx fragment at /etc/nginx/site-headers.conf, which is included inside the server block. nginx.conf is hand-maintainedand should hold nothing but boot-level things: root, index, error_page and a few regex redirects. One principle governs the split: anything the build can regenerate belongs in _headers; only boot-level needs stay in nginx.conf. All three bugs landed on that boundary.
First: an error_page that points at a file that does not exist. Astro emits dist/404.html for the Chinese 404 page but dist/en/404/index.html for the English one - one template, two shapes, and that break in symmetry is easy to miss. So error_page 404 /404/index.html never resolves and every 404 falls through to the nginx page of its own, which means the site 404 with its navigation and its note about where things moved never actually shipped. The check is cheap: a request for a path that does not exist has to show the site own copy, not a bare nginx card.
Second: the order inside try_files. With directory output - one index.html per route - the sequence $uri then $uri.html lets the .html branch swallow directory routes. The correct order is $uri/ before $uri.html, with /404.html last as the fallback. When this is wrong the site looks like only the home page works, but what actually happened is that every directory route was probing for a notes.html that was never emitted.
Third: CSP hashes out of sync with the inline scripts. The site has two executable inline scripts (one in the head that reads the theme early, one module for the motion), and both hashes must appear in script-src; a mismatch produces no error, it simply stops the animation. Reconcile by extracting every inline body from dist/, hashing it with sha256 and comparing against _headers one by one; the application/ld+json blocks are non-executable, so they are neither declared nor blocked. Note also that edge-injected scripts count too: if the CDN appends a beacon at the end of the body it needs a place in script-src, otherwise every page carries one failed third-party request and contradicts the no-trackers line in the footer - in that case I just turn the injection off.
One more trade-off worth writing down. Running nginx as root in the container still allows securityContext to drop all capabilities and add back only what is needed: CHOWN (owner of the cache directory), DAC_OVERRIDE (log and cache access), SETUID and SETGID (spawning worker processes), NET_BIND_SERVICE (binding port 80). Each one maps to a requirement you can state out loud, instead of opening privileged and moving on. Pair that with a startupProbe owning the slow start (periodSeconds 3, failureThreshold 20) while the readinessProbe keeps a short timeout, spread two replicas with podAntiAffinity, and a static site gets a zero-downtime rollout across two nodes.
A list worth copying: every error_page target must exist in dist (check with ls, not from memory); only regenerable settings belong in _headers; inline-script hashes come from the build, never a second hand calculation; edge-injected scripts need a CSP entry or should be switched off; and every capability must be able to name the reason it is there.