Skip to content

fix: disable nginx proxy buffering to enable AI streaming responses#1600

Merged
gugu merged 1 commit into
mainfrom
nginx-buffering-only
Feb 15, 2026
Merged

fix: disable nginx proxy buffering to enable AI streaming responses#1600
gugu merged 1 commit into
mainfrom
nginx-buffering-only

Conversation

@gugu

@gugu gugu commented Feb 15, 2026

Copy link
Copy Markdown
Contributor

Nginx was buffering the entire backend response before forwarding it to the client, preventing SSE streaming on the /ai/v4/request endpoint.

Nginx was buffering the entire backend response before forwarding it to the
client, preventing SSE streaming on the /ai/v4/request endpoint.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 15, 2026 12:48
@gugu gugu enabled auto-merge (squash) February 15, 2026 12:48
@gugu gugu merged commit 3e5434f into main Feb 15, 2026
21 checks passed
@gugu gugu deleted the nginx-buffering-only branch February 15, 2026 12:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a critical issue preventing Server-Sent Events (SSE) streaming on AI endpoints by configuring nginx to disable response buffering. The backend uses SSE to stream AI-generated responses incrementally to clients, but nginx was buffering the entire response before forwarding it, defeating the purpose of streaming.

Changes:

  • Disabled nginx proxy buffering and caching for the /api/ location block
  • Added HTTP/1.1 protocol support and proper Connection header handling for persistent connections
  • Fixed indentation/formatting inconsistencies (tabs to spaces)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_set_header Connection '';
proxy_buffering off;

Copilot AI Feb 15, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding proxy_read_timeout configuration to prevent premature connection timeouts during long-running AI streaming responses. SSE connections can remain open for extended periods, and the default nginx timeout (60s) may cause issues with longer AI processing. Add something like proxy_read_timeout 300s; to allow sufficient time for AI responses.

Suggested change
proxy_buffering off;
proxy_buffering off;
proxy_read_timeout 300s;

Copilot uses AI. Check for mistakes.
proxy_pass http://localhost:3000/;
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_set_header Connection '';

Copilot AI Feb 15, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding proxy_set_header X-Accel-Buffering no; to explicitly disable nginx's internal buffering mechanism. While proxy_buffering off; disables the main buffering, X-Accel-Buffering provides an additional layer of control specifically designed for streaming responses and ensures no buffering occurs at any level in nginx.

Suggested change
proxy_set_header Connection '';
proxy_set_header Connection '';
proxy_set_header X-Accel-Buffering no;

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants