V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
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 ·
    913647909 · 2018-12-29 14:40:13 +08:00 · 2150 次点击
    这是一个创建于 1916 天前的主题,其中的信息可能已经有所发展或是发生改变。

    想要在 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 条回复    2018-12-29 16:43:59 +08:00
    coolloves
        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;
    ```
    coolloves
        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;
    MisakaTang
        3
    MisakaTang  
    OP
       2018-12-29 16:43:59 +08:00
    @coolloves #2 感谢大佬 解决了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1133 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 18:42 · PVG 02:42 · LAX 11:42 · JFK 14:42
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.