Skip to content

Instantly share code, notes, and snippets.

@brownian
Created July 16, 2024 11:58
Show Gist options
  • Save brownian/135ea0929bf3679927be574ac96fa5ee to your computer and use it in GitHub Desktop.
Save brownian/135ea0929bf3679927be574ac96fa5ee to your computer and use it in GitHub Desktop.
nginx: how to workaround "and"/"or" for geoip2 locations

This code will set $allowed_city to "yes" if request made from Ukraine (or any other allowed country) OR from Krakow (or any other allowed city).

In /etc/nginx/nginx.conf:

        geoip2 /path/to/GeoLite2-City.mmdb {
                $geoip2_data_city_name          city names en;
                $geoip2_data_country_iso_code   country iso_code;
        }

        map $geoip2_data_country_iso_code $allowed_country {
                default no;
                UA      yes;
        }

        map $geoip2_data_city_name $allowed_city {
                default $allowed_country;
                Krakow  yes;
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment