The original post: /r/nginx by /u/needed_a_better_name on 2025-03-03 02:07:33.

I want to exclude a bunch of IPs from appearing in my access logs, these IPs are for an uptime monitoring service. The access_log module allows to specify “if=condition” to include only certain entries: https://nginx.org/en/docs/http/ngx_http_log_module.html#access_log

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

A request will not be logged if the condition evaluates to “0” or an empty string.

My issue is that I have already made a long map/geo of IPs, but their values are “inverted” (I use it in other places in my configs for access control with an if() conditional) - can I specify an “if not” with the access_log setting? Or do my “yes” and “no” not evaluate to the right values?

I tried the following two forms of syntax without success:

access_log ... if=!$uptimerobot;
access_log ... if!=$uptimerobot;

nginx doesn’t complain at config reload, but my the conditional doesn’t seem to work either and just keeps logging.

Ubuntu 24.04, nginx/1.24.0 (Ubuntu)

Config snippets:

conf.d/geoip.conf

geo $remote_addr $uptimerobot {
    default           no;
    216.144.250.150   yes;
    69.162.124.226   yes;
    69.162.124.227   yes;
    69.162.124.228   yes;
    ...
}

nginx.conf

http {
    ...
    include /etc/nginx/conf.d/*.conf;
    access_log /var/log/nginx/access.log vcombined if=!$uptimerobot;
    include /etc/nginx/sites-enabled/*;
}