Nginx acces日志乱码

logstash中将nginxaccess log,转化成json时,发现抛异常。
原因接口的request_body传的事json,但打印日志的时候,json的"转成\x22了,导致日志不是标准 json 格式了。
只需要在日志配置中新增escape=json

nginx.conf 配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
log_format aka_logs escape=json
'{"@timestamp":"$time_iso8601",'
'"host":"$hostname",'
'"server_ip":"$server_addr",'
'"client_ip":"222.241.119.99",'
# '"client_ip":"$remote_addr",'
'"xff":"$http_x_forwarded_for",'
'"domain":"$host",'
'"url":"$uri",'
'"referer":"$http_referer",'
'"args":"$args",'
'"upstreamtime":"$upstream_response_time",'
'"responsetime":"$request_time",'
'"request_method":"$request_method",'
'"status":"$status",'
'"size":"$body_bytes_sent",'
'"request_body":"$request_body",'
'"request_length":"$request_length",'
'"protocol":"$server_protocol",'
'"upstreamhost":"$upstream_addr",'
'"file_dir":"$request_filename",'
'"http_user_agent":"$http_user_agent"'
'}';

资料
Module ngx_http_log_module
nginx日志中$request_body 十六进制字符(\x22\x9B\x5C\x09\x08…)完美解决方案
nginx access 日志字符编码问题 \x22