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


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

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

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

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;
}

这里过滤掉了HEAD和OPTIONS请求

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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM