Question

How to use $geoip_city on Nginx

I have nginx-1.12.1 installed on Centos 6.7 final. Already loaded the --with-http_geoip_module on configure arguments.

I have this code on my nginx.conf inside http context

geoip_city     /usr/local/share/GeoIP/GeoLiteCity.dat;

Also add this code

map $geoip_city $not_allowed_region {
    default no;
    Shanghai yes;
}

Inside my vhost conf file

# server content
if ($not_allowed_region = yes) {
   rewrite ^/(.*)$ https://test.com redirect;
}

I did nginx -t and also restart using nginx -s reload but nothing happens.

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi @meowmanijado

Are you using an updated GeoLiteCity.dat ? Also remember that a lot of connections are now IPv6, so you need to use the GeoLiteCityv6.dat: https://dev.maxmind.com/geoip/legacy/geolite/