events { worker_connections 1024; } http { # SSE and MP3 streaming — no buffering, long timeouts upstream backend { server backend:8080; } upstream web { server web:3000; } server { listen 80; client_max_body_size 16m; # SSE overlay stream location ~ ^/api/overlay/[^/]+/stream { proxy_pass http://backend; 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_buffering off; proxy_cache off; proxy_read_timeout 120s; proxy_set_header Connection ''; chunked_transfer_encoding on; } # MP3 proxy — large bodies, streaming location /api/proxy/mp3 { proxy_pass http://backend; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Range $http_range; proxy_set_header If-Range $http_if_range; proxy_buffering off; proxy_cache off; proxy_read_timeout 300s; } # All other API calls location /api/ { proxy_pass http://backend; 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_read_timeout 30s; } # Next.js app (with WebSocket for hot reload in dev) location / { proxy_pass http://web; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_read_timeout 60s; } } }