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
 |
|
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;
|
 |
|
2
keepfun Sep 23, 2017 via iPhone
有个 nginx_log 插件,可以实现
|
 |
|
3
lerry Sep 23, 2017
location / { if ($http_user_agent ~* (Chrome\/50\.0\.2661\.102|MSIE\ 9\.0) ) { access_log off; return 403; } }
我这样写是好使的,注意转义
|
 |
|
4
ayiis Sep 23, 2017
放在 location 里是没问题的,可能是正则没写好?
|