I have a Flask backend running inside Docker, and it streams AI responses using a generator.
Locally it works perfectly, but after deploying with Nginx + Docker Compose, the streamed response gets cut off halfway.
Nginx config:
proxy_buffering off;
proxy_cache off;
proxy_read_timeout 300s;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header X-Accel-Buffering no;
default
Flask endpoint:
return Response(
ai_sdk_stream_generator(),
mimetype='text/plain',
headers={'X-Accel-Buffering': 'no', 'Connection': 'keep-alive'}
)
main
Issue:
Inside Docker, Nginx randomly stops sending chunks to the client. Flask continues printing chunks in logs, but the browser stops receiving them. No timeout logs or errors.
Tried:
disabling buffering
increasing timeouts
chunked transfer