Welcome! Log In Create A New Profile

Advanced

Conditional Logging on more than one constraint

Posted by plutocrat 
Conditional Logging on more than one constraint
November 30, 2017 01:24AM
Hi,

So the conditional logging example on nginx website is this, which I've tried, and it works as advertised.

-----------
map $status $loggable {
~^[23] 0;
default 1;
}

access_log /path/to/access.log combined if=$loggable;[/quote]
-----------

What happens if I also want to stop logging for clients with the User Agent "Zabbix"? If I try this ...

-----------------
map $status $loggable {
~^[23] 0;
default 1;
}

map $http_user_agent $loggable {
Zabbix 0;
default 1;
}

access_log /path/to/access.log combined if=$loggable;
---------------

... then the first map is superceded by the second, i.e. the $status is ignored and only the $http_user_agent is used to decide what is logged.

Whats the trick for setting $loggable=0 for both cases?
Re: Conditional Logging on more than one constraint
November 30, 2017 03:14AM
Use a third Map which does an OR or an AND on other map variables in to a new single variable for use.

map $http_user_agent $logv1 {
...
}

map $http_user_agent $logv2 {
...
}

map $http_user_agent $logv3 {
$logv1 0;
$logv2 1;
}

---
nginx for Windows http://nginx-win.ecsds.eu/
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 56
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready