yuan10
V2EX  ›  NGINX

关于 nginx 日志格式“乱码”问题

By yuan10 at 2019 年 8 月 23 日 · 5044 次点击

nginx 版本 1.14.0,使用 lua-nginx-module 输出 resp body ;

# 默认情况下日志输出 resp_body 里面的引号都被转成\x22
"xxx.xxx.xx.xx" "-" "23/Aug/2019:02:34:23 +0000" "POST /tes/api HTTP/1.1" "200" "67" "-" "Python/3.6 aiohttp/3.5.4" "-" "0.004" "{\x22success\x22: \x22true\x22, \x22sysTime\x22: 1566527663202, \x22data\x22: \x220976604866\x22}"
# 在 log_format 加上 escape=none 后,resp_body 输出正常,但是空字段变为“”,我想要的是“-”
"xxx.xxx.xx.xx" "" "23/Aug/2019:02:18:21 +0000" "POST /tes/api HTTP/1.1" "200" "67" "" "Python/3.6 aiohttp/3.5.4" "" "0.004" "{"success": "true", "sysTime": 1566526701825, "data": "0976604866"}"
# 我想要输出的结果是这样
"xxx.xxx.xx.xx" "-" "23/Aug/2019:02:35:21 +0000" "POST /tes/api  HTTP/1.1" "200" "67" "-" "Python/3.6 aiohttp/3.5.4" "-" "0.005" "{"success": "true", "sysTime": 1566527721618, "data": "0976604866"}"

通过修改 ngx_http_log_module.c 源码可以实现第三个结果,我想知道有没有办法不改源码,只通过配置实现?

2 条回复  •  2019-08-23 11:09:53 +08:00
fancy20
   1
fancy20  
   2019 年 8 月 23 日
fancy20
   2
fancy20  
   2019 年 8 月 23 日
没有测试过,只是看到这个配置
› NGINX
› NGINX Trac
› 3rd Party Modules
› Security Advisories
› CHANGES
› OpenResty
› ngx_lua
› Tengine
在线学习资源
› NGINX 开发从入门到精通
NGINX Modules
› ngx_echo
© 2026 V2EX · 36ms · 3.9.8.5