Heuristic:A616567126 GPT WEB JAVA SSE Nginx Buffer Disable
| Knowledge Sources | |
|---|---|
| Domains | Optimization, Networking |
| Last Updated | 2026-10-13 18:00 GMT |
Overview
Disable Nginx proxy buffering when deploying GPT-WEB-JAVA behind a reverse proxy to ensure SSE streaming responses reach the client without delay.
Description
The GPT-WEB-JAVA application uses Server-Sent Events (SSE) for streaming GPT chat responses to the frontend. SSE works by keeping an HTTP connection open and sending data chunks as they arrive from the OpenAI API. When Nginx is used as a reverse proxy in front of the Spring Boot application, its default behavior is to buffer proxy responses. This buffering causes SSE chunks to accumulate in Nginx's buffer before being forwarded to the client, effectively defeating the streaming mechanism — the user sees nothing until the entire response is complete, or sees large delayed chunks. The README explicitly warns: "若使用 Nginx 部署请务必关闭 Buffer 缓存" (When deploying with Nginx, be sure to disable buffer caching).
Usage
Use this heuristic when deploying GPT-WEB-JAVA (or any SSE-based application) behind an Nginx reverse proxy. Add `proxy_buffering off` to the Nginx location block that handles SSE endpoints. This is critical for the GPT streaming chat (`/gpt/*`) and SSE controller (`/sse/*`) endpoints.
The Insight (Rule of Thumb)
- Action: Set `proxy_buffering off;` in the Nginx location block for SSE endpoints.
- Value: Nginx directive `proxy_buffering off`.
- Trade-off: Disabling buffering slightly increases network overhead (more, smaller packets) but is essential for real-time streaming UX. No downside for SSE endpoints.
- Compatibility: Also set `proxy_cache off;` and consider `X-Accel-Buffering: no` response header as a fallback.
Reasoning
SSE (Server-Sent Events) relies on incremental HTTP response delivery. The client processes each `data:` line as it arrives. Nginx's default `proxy_buffering on` collects the upstream response into memory/file buffers before forwarding to the client, which transforms a streaming response into a batch response. For GPT chat, this means the user sees the full answer appear all at once (after the entire OpenAI API response completes) instead of word-by-word. Disabling buffering ensures each SSE chunk is forwarded immediately, preserving the streaming UX.
Example Nginx config:
location /gpt/ {
proxy_pass http://127.0.0.1:8081;
proxy_buffering off;
proxy_cache off;
proxy_set_header Connection '';
proxy_http_version 1.1;
chunked_transfer_encoding off;
}