$request_body hex character (\\x22) quotation mark problem processing record in Nginx log

Source: Internet
Author: User

When using Nginx to log access logs, it is found that when a PUT, POST request containing request_body, the log contains x22x9bx5cx09x08 characters, which is not conducive to reading and processing. For specific HTTP method support Request_body see http1.1 definition9Method definitions and payloads of HTTP Request methodsnginx.conf default Access_log configuration Log_format main'$remote _addr-$remote _user [$time _local] "$request"'                      '$status $body _bytes_sent "$http _referer"'                      '"$http _user_agent" "$http _x_forwarded_for "'                      '$http _host $upstream _status $upstream _addr $request _time $upstream _response_time'; change to Log_format Json_log escape=json'{"Realip": "$remote _addr", "@timestamp": "$time _iso8601", "host": "$http _host", "Request": "$request", "Req_body": "$request _body", "status": "$status", "size": $body _bytes_sent, "ua": "$http _user_agent", "Cookie": "$http _cookie", " Req_time ":" $request _time "," uri ":" $uri "," Referer ":" $http _referer "," Xff ":" $http _x_forwarded_for "," Ups_status ":" $ Upstream_status "," ups_addr ":" $upstream _addr "," Ups_time ":" $upstream _response_time "}'reference how to generate a JSON log fromNginx Official Document Ngx_http_log_module.html#Log_formatnote that escape is from1.11.8after the new parameters. If the older version of Linux can be considered using shell command replacement, Logstash can consider using Ruby processing, reference optionally support handling of x escape codes blog https:anjia.ml/2017/06/21/nginx-logging-request-body-as-hexidecimal/Jane Book http:www.jianshu.com/p/8409f28f32e9 Nuggets https:Juejin.im/post/5949e0f7128fe1006a627cc0

$request_body hex character (\\x22) quotation mark problem processing record in Nginx log

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.