V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
yuan10
V2EX  ›  NGINX

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

  •  
  •   yuan10 · 2019-08-23 11:01:36 +08:00 · 3816 次点击
    这是一个创建于 1679 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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-08-23 11:07:46 +08:00
    fancy20
        2
    fancy20  
       2019-08-23 11:09:53 +08:00
    没有测试过,只是看到这个配置
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   957 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 21:43 · PVG 05:43 · LAX 14:43 · JFK 17:43
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.