server { listen 80; listen [::]:80; server_name _; root /usr/share/nginx/html; index index.html; # Compression (spec-v8 §3): the image ships gzip enabled, but gzip_types # defaults to text/html only — the audit measured the hashed JS/CSS # uncompressed. Long-lived immutable caching for hashed assets stays as # it was; only the transfer encoding changes. gzip on; gzip_types text/css application/javascript application/json image/svg+xml text/xml application/xml; gzip_min_length 1024; gzip_vary on; gzip_comp_level 6; # Security headers (spec-v8 §3). nginx gotcha: add_header is NOT inherited # into a block that declares its own add_header — the index.html and asset # blocks set Cache-Control, so those two repeat the set verbatim. # CSP is deliberately the Report-Only header (spec-v8 D5): watch the # browser console on a real page, then drop the "-Report-Only" suffix to # enforce. style-src needs 'unsafe-inline' because motion writes inline # style attributes; there are no third-party script or image origins. # script-src carries the SHA-256 of the theme-init inline script in # index.html — the hash is verified against the built bytes by # scripts/generate-route-pages.ts: editing that script (or vite adding # one) fails the build and prints the new hash to paste here. add_header Content-Security-Policy-Report-Only "default-src 'self'; script-src 'self' 'sha256-FlEXeas8Ye/eeYFpd9EIm0va9LsSvF9SetK7HmeJMUQ='; style-src 'self' 'unsafe-inline'; img-src 'self' data:; frame-ancestors 'none'; base-uri 'self'; form-action 'self'" always; add_header Strict-Transport-Security "max-age=31536000" always; add_header X-Content-Type-Options "nosniff" always; add_header Referrer-Policy "strict-origin-when-cross-origin" always; add_header Permissions-Policy "geolocation=(), camera=(), microphone=()" always; add_header X-Frame-Options "DENY" always; # SPA routing with genuine 404s (spec-v8 §2.1): known routes are real # files — `pnpm generate:routes` writes dist//index.html for every # manifest route and project page. The first try_files parameter is the # composite file path, not the bare directory: '/about' is served from # dist/about/index.html with a 200 at the exact URL — no trailing-slash # 301, so canonical, internal links and sitemap URLs stay identical # strings (the audit's consistency point). Unknown URLs fall to =404, # answered with the generated 404 page at a real 404 status. # The coupling is guarded in generate-sitemap.ts: a sitemap URL without # its generated file fails the build before deploy. location / { try_files $uri/index.html $uri =404; } error_page 404 /404.html; # Do not aggressively cache index.html. # It references the latest hashed JS/CSS files. location = /index.html { try_files $uri =404; # add_header here ends the inheritance of the server-level set — # the security headers are repeated, not replaced (spec-v8 §3). add_header Content-Security-Policy-Report-Only "default-src 'self'; script-src 'self' 'sha256-FlEXeas8Ye/eeYFpd9EIm0va9LsSvF9SetK7HmeJMUQ='; style-src 'self' 'unsafe-inline'; img-src 'self' data:; frame-ancestors 'none'; base-uri 'self'; form-action 'self'" always; add_header Strict-Transport-Security "max-age=31536000" always; add_header X-Content-Type-Options "nosniff" always; add_header Referrer-Policy "strict-origin-when-cross-origin" always; add_header Permissions-Policy "geolocation=(), camera=(), microphone=()" always; add_header X-Frame-Options "DENY" always; add_header Cache-Control "no-cache, must-revalidate"; } # Vite-generated assets normally contain content hashes. # They can safely be cached for a long time. location ~* \.(?:css|js|mjs|map|png|jpg|jpeg|gif|svg|ico|webp|avif|woff|woff2|ttf|otf)$ { try_files $uri =404; expires 30d; # Same repetition rule as the index.html block above. add_header Content-Security-Policy-Report-Only "default-src 'self'; script-src 'self' 'sha256-FlEXeas8Ye/eeYFpd9EIm0va9LsSvF9SetK7HmeJMUQ='; style-src 'self' 'unsafe-inline'; img-src 'self' data:; frame-ancestors 'none'; base-uri 'self'; form-action 'self'" always; add_header Strict-Transport-Security "max-age=31536000" always; add_header X-Content-Type-Options "nosniff" always; add_header Referrer-Policy "strict-origin-when-cross-origin" always; add_header Permissions-Policy "geolocation=(), camera=(), microphone=()" always; add_header X-Frame-Options "DENY" always; add_header Cache-Control "public, max-age=2592000, immutable"; } location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } # Content write path (spec-v4 §6.2, spec-v4-deploy-infra D11/D13, spec-v6 D4): # Basic-auth at the proxy; ${CONTENT_API_TOKEN} and ${CONTENT_API_BASE} are # substituted by the image's envsubst template step from the container # environment (sourced from the stack's secrets/site_config) BEFORE nginx parses # this file — so proxy_pass below is a literal upstream once rendered, exactly as # it was when the URL was written here. The SPA bundle and the repository never # carry the token or the git host. location /api/content/ { auth_basic "Editor"; auth_basic_user_file /etc/nginx/htpasswd; # HTTP/2 to the upstream (nginx >= 1.29.4; the stack runs 1.31.x; the API host # answers an h2 ALPN handshake — verified against api.github.com 2026-10-26). The # edit-mode client issues its 12 document reads + 2 label reads as one concurrent # wave, so those requests multiplex over a single upstream connection instead of # one HTTP/1.1 connection each. Upstream keepalive caching is already the default # since 1.29.7; the docs still require the Connection header to be cleared for a # reused upstream connection. # rerun workflow proxy_http_version 2; proxy_set_header Connection ""; proxy_pass ${CONTENT_API_BASE}; proxy_ssl_server_name on; # Bearer is the form the GitHub Contents API documents; the legacy "token" # prefix was Gitea's. proxy_set_header Authorization "Bearer ${CONTENT_API_TOKEN}"; } }