# Behind a TLS-terminating proxy (Traefik, NPM, Caddy) this nginx itself only # sees plain http: passing $scheme on would tell the backend "http" for an # https site. Keep what the outer proxy said, and fall back to our own scheme. map $http_x_forwarded_proto $sp_forwarded_proto { default $http_x_forwarded_proto; "" $scheme; } server { listen 80; server_name _; root /usr/share/nginx/html; index index.html; # SPA fallback location / { try_files $uri $uri/ /index.html; } # API proxy location /api/ { proxy_pass http://backend:5008; # $http_host, not $host: $host drops the port, so with the default # "5009:80" mapping the OIDC redirect URI the backend derives from it # pointed at port 80. proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # Without this uvicorn sees plain http even behind TLS, which would make # the OIDC redirect URI it derives wrong and the refresh cookie miss its # Secure flag. proxy_set_header X-Forwarded-Proto $sp_forwarded_proto; proxy_read_timeout 600s; # Stack backups (incl. volume data) can be large in both directions. client_max_body_size 0; proxy_request_buffering off; # A backup download carries its report in a response header; past the # default 4-8k header buffer nginx answers 502 for a backup that worked. proxy_buffer_size 16k; proxy_buffers 8 16k; } # WebSocket proxy location /ws/ { proxy_pass http://backend:5008; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $http_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 $sp_forwarded_proto; proxy_read_timeout 86400s; } # Basic security headers add_header X-Frame-Options "SAMEORIGIN" always; add_header X-Content-Type-Options "nosniff" always; add_header Referrer-Policy "strict-origin-when-cross-origin" always; }