Jul*_*éon 50 logging json nginx
我正在尝试从nginx生成JSON日志.
我知道像这样的解决方案,但我想记录的一些字段包括用户生成的输入(如HTTP标头),需要正确转义.
我知道2011年10月和2008年5月的nginx changelog条目说:
*) Change: now the 0x7F-0x1F characters are escaped as \xXX in an
access_log.
*) Change: now the 0x00-0x1F, '"' and '\' characters are escaped as \xXX
in an access_log.
Run Code Online (Sandbox Code Playgroud)
但是这仍然没有帮助,因为\xXX
是在一个JSON字符串无效.
我还查看了具有set_quote_json_str
指令的HttpSetMiscModule模块,但这似乎只是添加\x22
了无效的字符串.
是否有其他解决方案可以从nginx登录JSON格式?
pva*_*pva 97
最后看起来我们有很好的方法可以在没有任何模块的情况下使用vanilla nginx.只需定义:
log_format json_combined escape=json
'{'
'"time_local":"$time_local",'
'"remote_addr":"$remote_addr",'
'"remote_user":"$remote_user",'
'"request":"$request",'
'"status": "$status",'
'"body_bytes_sent":"$body_bytes_sent",'
'"request_time":"$request_time",'
'"http_referrer":"$http_referer",'
'"http_user_agent":"$http_user_agent"'
'}';
Run Code Online (Sandbox Code Playgroud)
请注意,在nginx 1.11.8中添加了escape = json. http://nginx.org/en/docs/http/ngx_http_log_module.html#log_format
归档时间: |
|
查看次数: |
23450 次 |
最近记录: |