--- author: AI Assistant created_at: 2026-07-21 purpose: 记录 nginx 配置优化,禁用 SSE 响应缓冲 --- # nginx 配置优化 - ShortNovel SSE **文件:** `/etc/nginx/sites-enabled/lifescript.happylifeos.com.conf` **变更内容:** 在 `location /api/shortNovel/` 块中使用以下配置: - `proxy_http_version 1.1;` - 确保 SSE 长连接使用 HTTP/1.1 - `proxy_buffering off;` - 禁用代理缓冲 - `chunked_transfer_encoding on;` - 启用分块传输编码 - `proxy_set_header Connection "keep-alive";` - 保持上游连接 **原因:** - nginx 默认启用 `proxy_buffering on`,会缓冲后端响应 - 对于 SSE(Server-Sent Events)长连接,缓冲会导致事件无法立即到达前端 - 禁用缓冲后,每个事件都能立即转发给客户端,实现真正的流式传输 **验证:** - nginx 语法检查通过:`nginx -t` → syntax is ok / test is successful - nginx 重载成功:worker 进程已更新 - 使用 `curl -N https://lifescript.happylifeos.com/api/shortNovel/stream` 测试 SSE 流式传输 **备份文件:** `/etc/nginx/sites-enabled/lifescript.happylifeos.com.conf.backup.20260721_233252` **管理方式:** 宝塔面板,通过 `/etc/init.d/nginx reload` 重载配置