Introduction
Server-Sent Events, AI token streams, and other incremental HTTP responses need immediate flushes from upstream to browser. Nginx proxy buffering can coalesce those chunks and release them only after enough data accumulates, which makes a live stream appear frozen or delayed even though the upstream app is sending events continuously.
Symptoms
- EventSource connections open but updates arrive in large bursts instead of live
- Streaming responses work locally but stall behind Nginx
- Browsers show pending network requests while no visible tokens or events appear
- The issue affects only the proxied environment, not direct upstream access
Common Causes
- Nginx proxy buffering is enabled on the streaming endpoint
- Upstream responses are compressed or buffered before reaching Nginx
- The application does not send the correct SSE headers
- A CDN or second proxy in front of Nginx adds another buffering layer
Step-by-Step Fix
- 1.Confirm the stream works when bypassing Nginx
- 2.Test the upstream directly first so you know whether buffering is really introduced at the proxy layer.
curl -N http://127.0.0.1:3000/events- 1.Disable proxy buffering on the streaming location
- 2.SSE and chunked streaming endpoints need immediate pass-through instead of buffered proxy behavior.
location /events {
proxy_pass http://app_backend;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_buffering off;
proxy_cache off;
chunked_transfer_encoding on;
}- 1.Verify the upstream sends streaming-friendly headers
- 2.The application should identify the response as an event stream and avoid buffering headers of its own.
Content-Type: text/event-stream
Cache-Control: no-cache
Connection: keep-alive- 1.Re-test from the public URL and watch events arrive in real time
- 2.Use a no-buffering client such as
curl -Nafter the Nginx reload so you can see whether chunks now pass through immediately.
nginx -t && systemctl reload nginx
curl -N https://example.com/eventsPrevention
- Treat streaming routes differently from normal JSON API routes in proxy config
- Disable proxy buffering explicitly on SSE and token-stream endpoints
- Test live streaming through every proxy layer before release
- Document which routes require chunked pass-through behavior