网上很多教程说是这样做:

if ($request_method = HEAD) {
    access_log off;
}

试了之后是不行的,正确的做法如下:

nginx过滤access_log中HEAD、OPTIONS请求记录
http {
    map $request_method $loggable {
        HEAD 0;
        OPTIONS 0;
        default 1;
    }

    log_format main '$remote_addr [$time_local] $request $status $body_bytes_sent $http_user_agent';
    access_log /var/log/nginx/access.log main if=$loggable;
}
nginx过滤access_log中HEAD、OPTIONS请求记录

这里过滤掉了HEAD和OPTIONS请求

官方文档地址:http://nginx.org/en/docs/http/ngx_http_log_module.html

nginx过滤access_log中HEAD、OPTIONS请求记录

 

网上很多教程说是这样做:

if ($request_method = HEAD) {
    access_log off;
}

试了之后是不行的,正确的做法如下:

nginx过滤access_log中HEAD、OPTIONS请求记录
http {
    map $request_method $loggable {
        HEAD 0;
        OPTIONS 0;
        default 1;
    }

    log_format main '$remote_addr [$time_local] $request $status $body_bytes_sent $http_user_agent';
    access_log /var/log/nginx/access.log main if=$loggable;
}
nginx过滤access_log中HEAD、OPTIONS请求记录

这里过滤掉了HEAD和OPTIONS请求

官方文档地址:http://nginx.org/en/docs/http/ngx_http_log_module.html

nginx过滤access_log中HEAD、OPTIONS请求记录

 

相关文章:

  • 2022-12-23
  • 2021-09-18
  • 2021-07-27
  • 2022-12-23
  • 2021-10-03
  • 2022-12-23
  • 2022-01-21
  • 2021-07-05
猜你喜欢
  • 2022-12-23
  • 2021-10-04
  • 2021-05-31
  • 2021-11-28
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案