nginx log problem (\ x22)

# log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent $request_body "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';

log_format main escape=json '[$time_iso8601]|$remote_addr|$request_method|$request|$status|$body_bytes_sent|$request_body|$request_time|$request_body|'
'"$http_referer"|"$http_user_agent"|$http_x_forwarded_for|'
'"$upstream_addr"|$upstream_response_time|'
'$upstream_cache_status|$scheme|$http_user_agent';


access_log logs/access.log main;

 

 

https://www.cnblogs.com/dance-walter/p/10635260.html

nginx log problem (\ x22)

problem:

1, request_body contain Chinese, nginx logs are converted to hexadecimal.
2, nginx recording problem

POST /xxxxx HTTP/1.1|200|4266|0.121|0.121|------------------------------4a74a6c5ef13\x0D\x0AContent-Disposition: form-data; name=\x22city\x22\x0D\x0A\x0D\x0Ananjing\x0D\x0A------------------------------4a74a6c5ef13\x0D\x0AContent-Disposition: form-data; name=\x22service_name\x22\x0D\x0A\x0D\x0AgdmmGoods\x0D\------------------4a74a6c5ef13\x0D\x0AContent-Disposition: form-data; name=\x22canUseCoupon\x22\x0D\x0A\x0D\x0A1\x0D\x0A------------------------------4a74a6c5ef13--\x0D\x0A|-|-|-|-|xxx|https

optimization:

logstash order to efficiently handle various types of logs, the log is desirable manner a particular storage configuration.


nginx default log format:

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for" $request_body'; 

Issue Log

[25/Feb/2019:00:00:10 +0800]|192.168.10.19|POST /paas/callback HTTP/1.1|200|163|0.002|0.002|{\x22rc\x22:0,\x22msg\x22:\x22success\x22,\x22transferrate\x22:\x2245301\x22}]}}

request_bodyIt is converted in hexadecimal after and difficult to read.


Provide direct visualization of the log and resolve hexadecimal format solutions:

Formatted data:

###json格式:
    log_format log_json escape=json '{"timestamp": "$time_local",'
        '"remote_addr": "$remote_addr",' '"referer": "$http_referer",' '"request": "$request",' '"statu": "$status",' '"byte": "$body_bytes_sent",' '"agen": "$http_user_agent",' '"x_forwarde": "$http_x_forwarded_for",' '"up_addr": "$upstream_addr",' '"up_host": "$upstream_http_host",' '"up_resp_time": "$upstream_response_time",' '"request_time": "$request_time"}'; ###自定义边界: log_format main escape=json '[$time_iso8601]|$remote_addr|$request_method|$request|$status|$body_bytes_sent|$request_time|$request_body|' '"$http_referer"|"$http_user_agent"|$http_x_forwarded_for|' '"$upstream_addr"|$upstream_response_time|' '$upstream_cache_status|$scheme|$http_user_agent';
  • log_format: beginning of the log format
  • main: Log Name
  • escape = json: nginx 1.11.8 version is not available until this parameter. link

If the version is low, either upgrade, or use the ruby in logstash to do a conversion, refer to the link: https://github.com/logstash-plugins/logstash-codec-json/issues/2

Question 2:

When the above-described error occurs nginx, the initiator must not normally encoded data (Content-Type request is initiated by the default multipart / form-data).
Solutions when submitting data in the POST encode the data (Content-Type: application / x -www-form-urlencoded)
link: https: //stackoverflow.com/questions/4007969/application-x-www-form-urlencoded-or -multipart-form-data / 4073451 # 4073451

Guess you like

Origin www.cnblogs.com/zhoading/p/12505444.html