想要在 nginx 上屏蔽掉 OPTIONS 请求不写到 accesslog 里去,然后参照https://blog.rooot.me/p/nginx_access_log_filter.html这篇文章写了如下的配置:
set $logfile /log/xxxx.log ;
if ($request_method = OPTIONS ){
set $logfile /dev/null ;
}
access_log /$logfile ;
但是配置不生效,求解答
1
coolloves 2018-12-29 16:24:10 +08:00
```
以下放到 http 字段内 map $request_method $log{ OPTIONS 0 ; default 1 ; } 以下放到 server 下 access_log logs/access.log main if=$log; ``` |
2
coolloves 2018-12-29 16:39:30 +08:00 1
http://nginx.org/en/docs/http/ngx_http_log_module.html
The if parameter (1.7.0) enables conditional logging. A request will not be logged if the condition evaluates to “ 0 ” or an empty string. In the following example, the requests with response codes 2xx and 3xx will not be logged: map $status $loggable { ~^[23] 0; default 1; } access_log /path/to/access.log combined if=$loggable; |
3
MisakaTang OP @coolloves #2 感谢大佬 解决了
|