Nginx访问日志在处理中文时,默认使用16进制编码处理。使我们对访问日志进行分析处理时,带来很大不便。含有中文字符的请求,日志记录如下:
171.43.238.62 - - [05/Dec/2017:21:40:57 +0800] "GET /xD6xD0xCExC4 HTTP/1.1" 404 171 "-" "curl/7.56.0"
问题解决方案:
- nginx版本需大于1.11.8
- 在定义 access log 格式时,加上
escape=json
日志格式示例:
log_format main escape=json '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
结果:
47.52.167.143 - [05/Dec/2017:21:55:59 +0800] "GET /中文 HTTP/1.1" 404 171 "" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2" ""
?
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!