[英]Nginx location or map to disable access log for specific GET argument
I've been trying to filter out a bunch of lines from the nginx access log. 我一直在尝试从nginx访问日志中过滤掉很多行。 These lines contain a specific parameter, so I thought it would be easy to filter them out.
这些行包含一个特定的参数,因此我认为将它们过滤掉很容易。 Examples of the requests:
请求示例:
/index.php?cmd=thumb&#####
/index.php?cmd=preview&#####
where ##### can be anything. #####可以是任何东西。 /index.php without this 'cmd' parameter (but possibly with other parameters) SHOULD be logged however.
/index.php没有这个'cmd'参数(但是可能还有其他参数)应该被记录。
I have tried the following 我尝试了以下
server {
location ~ /index\.php\?cmd.* {
access_log off;
}
}
My guess is that location only looks at the file on the server you need, not any of the reuqest parameters. 我的猜测是,该位置仅查看您需要的服务器上的文件,而不查看任何reuqest参数。 That could, for example, explain why
location ~* \\.(?:css|js)$ {access_log off;}
(notice the $
) also blocks logging request like /something.js?v=blahblah
. 例如,这可以解释为什么
location ~* \\.(?:css|js)$ {access_log off;}
(注意$
)也会阻止日志记录请求,如/something.js?v=blahblah
。 As such, my first option would be invalid for sure. 因此,我的第一个选择肯定是无效的。 This is confirmed below (with source ).
这已在下面得到确认(带有来源 )。
or 要么
server {
location /index.php {
if ($arg_cmd) {
access_log off;
}
}
}
or 要么
http {
map $request_uri $log {
~ /index\.php\?cmd.* 0;
default 1;
}
access_log /var/log/nginx/access.log combined if=$log;
}
So far, all of the above do not have the desired result. 到目前为止,上述所有方法均未达到预期的效果。 I'm still convinced this should be possible and that I did something wrong in all of these implementations.
我仍然坚信这是可能的,并且在所有这些实现中我做错了什么。 Could someone please help me out?
有人可以帮我吗?
if ($args ~ ^cmd=.+) {access_log off;}
if cmd is always the first argument, or just if ($args ~ cmd) {access_log off;}
. if ($args ~ ^cmd=.+) {access_log off;}
如果cmd始终是第一个参数,或者仅仅if ($args ~ cmd) {access_log off;}
。 (thx Richard Smith) ~
and /index\\.php\\?cmd.* 0;
~
和/index\\.php\\?cmd.* 0;
之间的空格来/index\\.php\\?cmd.* 0;
This one allows me to globally set some more conditions to ignore, so I'm sticking with this one.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.