From 4407e7ba737efcca934a9e84d1808e738f9dafe1 Mon Sep 17 00:00:00 2001 From: K-hermes Date: Sat, 15 Aug 2026 14:07:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=A4=A7=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E4=BD=93=E5=AF=BC=E8=87=B4=E7=9A=84=20Empty=20body=20?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题: - 当请求体超过 Nginx 缓冲区大小(默认较小)时 - ngx.req.get_body_data() 返回 nil - Nginx 会将请求体写入临时文件 解决: - 检查 ngx.req.get_body_file() 获取临时文件路径 - 从临时文件读取完整请求体 - 支持任意大小的请求体(通义听悟 ~100KB) 影响: - 修复通义听悟等数据量较大的网站同步失败问题 --- nginx/nginx.conf | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/nginx/nginx.conf b/nginx/nginx.conf index dfbb1ef..71be6f0 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -139,6 +139,18 @@ http { ngx.req.read_body() local body = ngx.req.get_body_data() + -- 如果 body 为空,可能是因为请求体被写入了临时文件 + if not body then + local body_file = ngx.req.get_body_file() + if body_file then + local file = io.open(body_file, "r") + if file then + body = file:read("*all") + file:close() + end + end + end + if not body then ngx.status = 400 ngx.say(cjson.encode({error = "Empty body"}))