首页 > 系统相关 >nginx过滤access_log中HEAD、OPTIONS请求记录

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

时间:2022-11-26 12:03:30浏览次数:70  
标签:HEAD http log access nginx OPTIONS

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

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

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

http {
map $request_method $loggable {
HEAD 0;
OPTIONS 0;
default 1;
}

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

access_log /usr/local/openresty/server/nginx/logs/access.log main if=$loggable;
}

 

这里过滤掉了HEAD和OPTIONS请求

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

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



标签:HEAD,http,log,access,nginx,OPTIONS
From: https://blog.51cto.com/u_6364219/5888799

相关文章