From feaf8922c5aaf4acb34da2b4edf8ab5c5eae3e81 Mon Sep 17 00:00:00 2001 From: Peanut Date: Tue, 21 Jul 2026 23:34:23 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E8=AE=B0=E5=BD=95=20nginx=20SSE=20?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2026-07-21-shortnovel-sse-optimization.md | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 docs/nginx-config-changes/2026-07-21-shortnovel-sse-optimization.md diff --git a/docs/nginx-config-changes/2026-07-21-shortnovel-sse-optimization.md b/docs/nginx-config-changes/2026-07-21-shortnovel-sse-optimization.md new file mode 100644 index 0000000..36e0f7f --- /dev/null +++ b/docs/nginx-config-changes/2026-07-21-shortnovel-sse-optimization.md @@ -0,0 +1,30 @@ +--- +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_buffering off;` - 禁用代理缓冲 +- `proxy_cache off;` - 禁用缓存 +- `chunked_transfer_encoding on;` - 启用分块传输编码 +- `proxy_set_header Connection '';` - 清除 Connection 头 + +**原因:** +- 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` 重载配置