server { listen 80; server_name localhost; root /usr/share/nginx/html; # Gzip compression gzip on; gzip_types text/plain text/css application/json application/javascript text/xml application/xml; # SvelteKit SPA routing location / { try_files $uri $uri/ /index.html; } # API proxy to backend location /api/ { proxy_pass http://backend:8080; 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; # SSE specific settings - critical for streaming proxy_set_header X-Accel-Buffering no; proxy_buffering off; proxy_cache off; chunked_transfer_encoding off; proxy_read_timeout 86400s; proxy_send_timeout 86400s; # Keep connection open for SSE proxy_set_header Connection ''; } # Health check location /health { proxy_pass http://backend:8080; } # Prometheus metrics endpoint location /metrics { proxy_pass http://backend:8080; } # Cache static assets location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ { expires 1y; add_header Cache-Control "public, immutable"; } }