# ----------------------------------------------------------------------------- # 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. # ----------------------------------------------------------------------------- server { listen 8080; server_name _; root /usr/share/nginx/html; index index.html; # --- Security headers ---------------------------------------------------- add_header X-Content-Type-Options "nosniff" always; add_header X-Frame-Options "DENY" always; add_header Referrer-Policy "strict-origin-when-cross-origin" always; add_header Permissions-Policy "camera=(), microphone=(), geolocation=(), interest-cohort=()" always; # The bundle is fully self-hosted, so the policy can stay strict. add_header Content-Security-Policy "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'" always; 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; add_header Content-Type text/plain; return 200 'ok'; } # Hashed assets never change under the same name - cache them hard. location /assets/ { expires 1y; add_header Cache-Control "public, immutable"; try_files $uri =404; } location /api/ { proxy_pass http://backend:8000; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Request-ID $request_id; proxy_connect_timeout 5s; proxy_read_timeout 30s; } # Django admin and API documentation share the backend origin. location ~ ^/(admin|static)/ { proxy_pass http://backend:8000; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } # Client-side routing: unknown paths fall back to the SPA shell. location / { try_files $uri $uri/ /index.html; add_header Cache-Control "no-cache"; } }