› 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 · 3043 views
    This topic created in 2871 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
    sparkssssssss
    Dec 29, 2018
    1
    ```
    以下放到 http 字段内
    map $request_method $log{
    OPTIONS 0 ;
    default 1 ;
    }

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