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

nginx 这样设置不记录某种日志,为什么不生效

  •  
  •   a523860 · Sep 23, 2017 · 6665 views
    This topic created in 3161 days ago, the information mentioned may be changed or developed.
    if ($http_user_agent ~* (abcd|123456789)) {
    access_log off; }
    这样不行

    location / { if ($http_user_agent ~* (abcd|123456789)) {
    access_log off; }
    }
    这样也不行

    要怎么写,我想设置不记录 某些 http_user_agent 访问的日志
    4 replies    2017-09-23 10:43:47 +08:00
    akira
        1
    akira  
       Sep 23, 2017   ❤️ 1
    access_log 的 off 只影响本层。试试用 access_log if=condition 格式
    map $status $loggable {
    abcd 0;
    123456789 0;
    default 1;
    }

    access_log /var/log/nginx/access.log combined if=$loggable;
    keepfun
        2
    keepfun  
       Sep 23, 2017 via iPhone
    有个 nginx_log 插件,可以实现
    lerry
        3
    lerry  
       Sep 23, 2017
    location / {
    if ($http_user_agent ~* (Chrome\/50\.0\.2661\.102|MSIE\ 9\.0) ) {
    access_log off;
    return 403;
    }
    }

    我这样写是好使的,注意转义
    ayiis
        4
    ayiis  
       Sep 23, 2017
    放在 location 里是没问题的,可能是正则没写好?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5535 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 03:06 · PVG 11:06 · LAX 20:06 · JFK 23:06
    ♥ Do have faith in what you're doing.