Forum: NGINX geoip filtering not working

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
bignginxfan (Guest)
on 2013-07-13 04:09
(Received via mailing list)

I'm trying to figure out why Nginx's geoip modules doesn't seem to
out certain ip's from a banned country. I manually tested the GeoIP.dat
using 'geoiplookup' against a few ips that successfully connected but
in a banned country. GeoIP.dat was fine, it wasn't the problem. Maybe
its a
config problem? Wondering if you guys can help.

i have the following lines in config:

geoip_country /usr/share/GeoIP/GeoIP.dat;

server {
    if ($geoip_country_code = CN) {
            return 444;

Please help!

Posted at Nginx Forum:,240802,240802#msg-240802
Matt520 (Guest)
on 2013-08-16 12:28
(Received via mailing list)
Hi, I was looking for the zip code from a given IP address few months
and now I've got the solution from IP2Location. You can try IP2Location
module see if it helps in your issues and good luck.

Posted at Nginx Forum:,240802,241917#msg-241917
AJ Weber (Guest)
on 2013-08-16 15:15
(Received via mailing list)
I have this working pretty well (ok, I think _very_well_ ) with GeoIP.

I used a MAP in the main nginx.conf like this:
     map $geoip_country_code $allowed_country {
         default    0;

         US         1;
         GB         1;
         CA         1;
         EU         1;

Then, in my default.conf, the first statement(s) in the relevant
"location's" is:

  if ($allowed_country = 0) {
             return 418;

Again, this works for me, and you can add "allowed countries" in just
one place: the "map".

This topic is locked and can not be replied to.