在nginx打印日志时,$request_body参数,当上传参数为文件流时,打印到日志里为乱码。
当前解决方案是根据$content_type去判断是否打印$request_body,暂时未找到其他更好的方法。
举例:
location ~/api/test/ {
proxy_pass http://127.0.0.1:7000;
add_header Access-Control-Allow-Origin *;
proxy_set_header logId $logid;
if ( $content_type ~* 'application/json' ){
#当content_type为application/json,使用带$request_body的日志format
access_log /data/nginx/logs/operate.log operatelog ;
}
if ( $content_type !~* 'application/json' ){
#当content_type不为application/json,使用不带$request_body的日志format
access_log /data/nginx/logs/operate.log otherlog ;
}
}