版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhangyunsheng11/article/details/83349458
Nginx处理请求后把关于客户端请求的信息写到访问日志。默认,访问日志位于 logs/access.log,写到日志的信息是预定义的、组合的格式。要覆盖默认的配置,使用log_format指令来配置一个记录信息的格式,同样使用access_log 指令到设置日志和格式和位置。格式定义使用变量。
1、自定义一个日志格式
log_format mylogformat '"$remote_addr" "[$time_local]" "$request_method" '
'"$uri" "$request_uri" "$request_time" "$status" "$body_bytes_sent"'
'"$http_referer" "$http_x_forwarded_for" "$http_user_agent" "$upstream_status"'
'"$upstream_addr" "$upstream_response_time"';
2、然后配置新的生成日志文件名:
access_log logs/access1.log mylogformat if=$loggable;
3、过滤掉需要过滤的日志,此处是过滤掉以2或者3开头的响应码
map $status $loggable {
~^[23] 0;
default 1;
}
具体配置如下图:
测试如下:
日志中不会输出200的错误