# nginx reverse proxy — single-origin deployment (SPEC §4). # Serves the built SPA and proxies /api, /health, /ready to the Express API # so the browser talks to exactly one origin (cookies stay SameSite=Lax safe). # Mounted read-only at /etc/nginx/nginx.conf by docker-compose.prod.yml. worker_processes auto; events { worker_connections 1024; } http { # Hide nginx version from error pages and Server headers. server_tokens off; include /etc/nginx/mime.types; default_type application/octet-stream; sendfile on; tcp_nopush on; keepalive_timeout 65; client_max_body_size 1m; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; error_log /var/log/nginx/error.log warn; # ---- Compression ---- gzip on; gzip_vary on; gzip_comp_level 6; gzip_min_length 1024; gzip_types text/plain text/css text/xml text/javascript application/javascript application/json application/xml application/rss+xml image/svg+xml; # ---- Security headers (inherited by every location unless a location sets # its own add_header, in which case it is re-declared there) ---- 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; upstream api { server api:4000; } server { listen 80; server_name _; root /usr/share/nginx/html; index index.html; # ---- API: forward the original URI untouched (/api/... -> /api/...) ---- # X-Forwarded-* headers let the API's TRUST_PROXY_HOPS resolve the real # client IP for rate limiting (SPEC §8.4). location /api/ { proxy_pass http://api; 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 Connection ""; proxy_buffering off; proxy_read_timeout 600s; } # ---- Public health / readiness (unversioned) ---- location = /health { proxy_pass http://api/health; 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; } location = /ready { proxy_pass http://api/ready; 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; } # ---- Hashed build assets: cache aggressively (immutable), never HTML ---- location ~* \.(?:js|css|map|svg|png|jpg|jpeg|gif|webp|ico|woff2?|ttf|eot)$ { expires 1y; add_header Cache-Control "public, max-age=31536000, immutable" always; 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; try_files $uri =404; } # ---- SPA fallback: everything else -> index.html (never cached) ---- location / { add_header Cache-Control "no-store" always; 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; try_files $uri $uri/ /index.html; } } }