# ----------------------------------------------------------------------------- # Serves the SPA and proxies /api to the Django container. # # Putting both behind one origin means the browser never issues a cross-origin # request, so no CORS pre-flight, no third-party cookie rules, and the API can # keep its allow-list empty in production. # # Every location includes security-headers.conf rather than relying on a # server-level declaration - see the comment in that file for why inheritance # cannot be trusted here. Proxied locations additionally include # proxy-backend.conf, which forwards the client details and drops the # duplicate security headers Django emits. # ----------------------------------------------------------------------------- # The SPA's policy: no inline script, nothing loaded off-origin. The bundle is # fully self-hosted, so this can stay strict. ('unsafe-inline' for styles is # still required by the inline style attributes React emits.) map $host $spa_csp { default "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self'; font-src 'self'; frame-ancestors 'none'; base-uri 'self'; form-action 'self'"; } server { listen 8080; server_name _; root /usr/share/nginx/html; index index.html; server_tokens off; client_max_body_size 2m; gzip on; gzip_types text/css application/javascript application/json image/svg+xml; gzip_min_length 1024; location = /healthz { access_log off; include /etc/nginx/conf.d/security-headers.conf; add_header Content-Type text/plain; return 200 'ok'; } # Hashed assets never change under the same name - cache them hard. location /assets/ { include /etc/nginx/conf.d/security-headers.conf; add_header Content-Security-Policy $spa_csp always; expires 1y; add_header Cache-Control "public, immutable"; try_files $uri =404; } # --- API documentation --------------------------------------------------- # Swagger UI and ReDoc bootstrap themselves from an inline