NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
MisakaTang
V2EX  ›  NGINX

nginx 配置文件问题:根据请求的类型来过滤 access log

  •  
  •   MisakaTang ·
    TangMisaka23001 · Dec 29, 2018 · 2672 views
    This topic created in 2691 days ago, the information mentioned may be changed or developed.

    想要在 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 ;
    

    但是配置不生效,求解答

    3 replies    2018-12-29 16:43:59 +08:00
    sparkssssssss
        1
    sparkssssssss  
       Dec 29, 2018
    ```
    以下放到 http 字段内
    map $request_method $log{
    OPTIONS 0 ;
    default 1 ;
    }

    以下放到 server 下
    access_log logs/access.log main if=$log;
    ```
    sparkssssssss
        2
    sparkssssssss  
       Dec 29, 2018   ❤️ 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;
    MisakaTang
        3
    MisakaTang  
    OP
       Dec 29, 2018
    @coolloves #2 感谢大佬 解决了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5910 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 02:34 · PVG 10:34 · LAX 19:34 · JFK 22:34
    ♥ Do have faith in what you're doing.