Report this

What is the reason for this report?

How to use $geoip_city on Nginx

Posted on July 25, 2017

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.



This textbox defaults to using Markdown to format your 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/

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.