I've been trying to filter out a bunch of lines from the nginx access log. 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.
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. That could, for example, explain why location ~* \.(?:css|js)$ {access_log off;}
(notice the $
) also blocks logging request like /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?