From 1d601c172a52504db79b7b85c77be42eee8cacd1 Mon Sep 17 00:00:00 2001 From: K-hermes Date: Sat, 15 Aug 2026 14:11:19 +0800 Subject: [PATCH] =?UTF-8?q?debug:=20=E5=A2=9E=E5=BC=BA=20JSON=20=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E9=94=99=E8=AF=AF=E7=9A=84=E8=B0=83=E8=AF=95=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 改进: - 记录接收到的请求体大小 - JSON 解析失败时返回详细错误信息 - 返回解析错误详情、body 大小、前 200 字符预览 - 在日志中记录前 500 字符,方便排查问题 --- nginx/nginx.conf | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/nginx/nginx.conf b/nginx/nginx.conf index 71be6f0..b4d4f68 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -157,11 +157,22 @@ http { return end + -- 记录请求体大小,方便调试 + ngx.log(ngx.INFO, "Received body size: ", string.len(body)) + -- 解析 JSON local ok, data = pcall(cjson.decode, body) if not ok then + -- 记录解析错误的详细信息 + ngx.log(ngx.ERR, "JSON parse error: ", data) + ngx.log(ngx.ERR, "Body preview (first 500 chars): ", string.sub(body, 1, 500)) ngx.status = 400 - ngx.say(cjson.encode({error = "Invalid JSON"})) + ngx.say(cjson.encode({ + error = "Invalid JSON", + details = tostring(data), + body_size = string.len(body), + body_preview = string.sub(body, 1, 200) + })) return end