Server-Sent Events / streaming responses work directly against the app, but through nginx they arrive all at once at the end.
IntermediateTroubleshootingLoad balancers and reverse proxies
Answer
Likely causes → nginx buffers upstream responses by default and only flushes when buffers fill or the response ends. Compression (gzip on) and some LBs add more buffering.
Diagnose →
curl -N http://127.0.0.1:8080/stream # direct: events trickle in
curl -N https://app.example.com/stream # via nginx: all at the end
Fix →
location /stream {
proxy_pass http://app;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_buffering off;
proxy_read_timeout 1h;
gzip off;
}
Or have the app send X-Accel-Buffering: no for streaming responses.
Prevent → Mark streaming endpoints explicitly in proxy config and include them in end-to-end tests through the real proxy chain.
More on Load balancers and reverse proxies
nginx returns `502 Bad Gateway` and the error log says `connect() failed (111: Connection refused) while connecting to upstream`.Beginnernginx returns `504 Gateway Time-out` with `upstream timed out (110: Connection timed out) while reading response header from upstream`.BeginnerAn ALB target group shows all targets `unhealthy` with `Health checks failed with these codes: [404]`.BeginnerAn ALB returns sporadic `502`s, and access logs show `elb_status_code=502` with `target_status_code=-`. Load is low.Intermediatenginx logs `upstream prematurely closed connection while reading response header from upstream`.Intermediatenginx error log shows `no live upstreams while connecting to upstream` and every request gets 502.Intermediate