2026-10-09 21:29:59 +07:00
|
|
|
server {
|
|
|
|
|
listen 80;
|
|
|
|
|
listen [::]:80;
|
|
|
|
|
|
|
|
|
|
server_name _;
|
|
|
|
|
|
|
|
|
|
root /usr/share/nginx/html;
|
|
|
|
|
index index.html;
|
|
|
|
|
|
2026-11-02 13:02:53 +07:00
|
|
|
# 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/<route>/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.
|
2026-10-09 21:29:59 +07:00
|
|
|
location / {
|
2026-11-02 13:02:53 +07:00
|
|
|
try_files $uri/index.html $uri =404;
|
2026-10-09 21:29:59 +07:00
|
|
|
}
|
|
|
|
|
|
2026-11-02 13:02:53 +07:00
|
|
|
error_page 404 /404.html;
|
|
|
|
|
|
2026-10-09 21:29:59 +07:00
|
|
|
# Do not aggressively cache index.html.
|
|
|
|
|
# It references the latest hashed JS/CSS files.
|
|
|
|
|
location = /index.html {
|
|
|
|
|
try_files $uri =404;
|
|
|
|
|
|
2026-11-02 13:02:53 +07:00
|
|
|
# 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;
|
2026-10-09 21:29:59 +07:00
|
|
|
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;
|
2026-11-02 13:02:53 +07:00
|
|
|
# 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;
|
2026-10-09 21:29:59 +07:00
|
|
|
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;
|
|
|
|
|
}
|
2026-10-22 09:55:21 +07:00
|
|
|
|
2026-10-26 20:49:34 +07:00
|
|
|
# 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.
|
2026-10-22 09:55:21 +07:00
|
|
|
location /api/content/ {
|
|
|
|
|
auth_basic "Editor";
|
|
|
|
|
auth_basic_user_file /etc/nginx/htpasswd;
|
|
|
|
|
|
2026-10-26 20:49:34 +07:00
|
|
|
# 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.
|
2026-10-26 21:46:13 +07:00
|
|
|
# rerun workflow
|
2026-10-24 14:45:26 +07:00
|
|
|
proxy_http_version 2;
|
|
|
|
|
proxy_set_header Connection "";
|
|
|
|
|
|
2026-10-26 20:49:34 +07:00
|
|
|
proxy_pass ${CONTENT_API_BASE};
|
2026-10-22 09:55:21 +07:00
|
|
|
proxy_ssl_server_name on;
|
2026-10-26 20:49:34 +07:00
|
|
|
# Bearer is the form the GitHub Contents API documents; the legacy "token"
|
|
|
|
|
# prefix was Gitea's.
|
|
|
|
|
proxy_set_header Authorization "Bearer ${CONTENT_API_TOKEN}";
|
2026-10-22 09:55:21 +07:00
|
|
|
}
|
2026-11-02 13:02:53 +07:00
|
|
|
}
|