E
E
e-hot2019-01-20 21:28:12
Nginx
e-hot, 2019-01-20 21:28:12

How to fix an error when building Nginx with GeoIP module?

Welcome all. I need your help.
Situation:
I'm trying to set up a server so that the site is available only for RF users, i.e. to make 403 forbidden open to all other countries.
I found a more or less understandable manual and did the following:
1. Checking nginx -V showed that --with-http_geoip_module exists and is already enabled
2. Downloaded sudo wget geolite.maxmind.com/download/geoip/database/GeoLit...
sudo wget geolite.maxmind.com/download/geoip/database/GeoLit...
3. Unpacked to /etc/nginx/geoip/ GeoLite2-Country.mmdb and GeoLite2-City.mmdb
4. Added to nginx.conf in http:

geoip_country /etc/nginx/geoip/GeoLite2-Country.mmdb;
geoip_city /etc/nginx/geoip/GeoLite2-City.mmdb;

map $geoip_country_code $bad_country {
    default 1;
    include /etc/nginx/geoip/good_countries;
}

5. In fastcgi_params added:
fastcgi_param  GEOIP_COUNTRY_CODE        $geoip_country_code;
fastcgi_param  GEOIP_COUNTRY_CODE3       $geoip_country_code3;
fastcgi_param  GEOIP_COUNTRY_NAME        $geoip_country_name;
fastcgi_param  GEOIP_CITY_COUNTRY_CODE   $geoip_city_country_code;
fastcgi_param  GEOIP_CITY_COUNTRY_CODE3  $geoip_city_country_code3;
fastcgi_param  GEOIP_CITY_COUNTRY_NAME   $geoip_city_country_name;
fastcgi_param  GEOIP_REGION              $geoip_region;
fastcgi_param  GEOIP_CITY                $geoip_city;
fastcgi_param  GEOIP_POSTAL_CODE         $geoip_postal_code;
fastcgi_param  GEOIP_CITY_CONTINENT_CODE $geoip_city_continent_code;
fastcgi_param  GEOIP_LATITUDE            $geoip_latitude;
fastcgi_param  GEOIP_LONGITUDE           $geoip_longitude;

6. Restarted sudo service nginx restart, the server replied:
fail
7. Tested the nginx -t settings, the server replied:
nginx: [emerg] invalid GeoIP City database "/etc/nginx/geoip/GeoLite2-City.mmdb" type:1 in /etc/nginx/nginx.conf:94
nginx: configuration file /etc/nginx/nginx.conf test failed

8. The answer refers specifically to the line:
geoip_city /etc/nginx/geoip/GeoLite2-City.mmdb;
has not yet moved further.
9. I understand that something is wrong with the specified database, but I didn’t find any similar situations on the Internet, I also tried to install the database in csv format - and in this case, nginx cursed again at the cities database (GeoLite2-City-Locations-ru .csv )
Question: if anyone has encountered a similar situation - tell me where and what is wrong. Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Syomov, 2019-01-20
@kotomyava

ngx_http_geoip_module does not support GeoIP2

You need data in an older format.
To solve your problem, you don't need City at all. And country can be delivered from the system repository in the desired format.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question