This tool converts the MaxMind GeoLite2 Country database into files suitable for the nginx geo and map modules.
It maps a client's IP address to a standard country code or to one of the following special country codes:
XX— Used when no country code is available for a client's IP address.T1— Used as a virtual country code for clients on the Tor network.
Important
Python 3.9+ and the requests module are required.
- Clone this repository into the
/opt/nginx-geodirectory:
cd /opt && git clone https://github.com/makhomed/nginx-geo.git nginx-geo- Create the
nginx-geo.tomlconfiguration file using one of the provided example files:
cd /opt/nginx-geo && cp nginx-geo.toml.maxmind.example nginx-geo.toml && vim nginx-geo.toml- Create the
/etc/cron.d/nginx-geofile with the following content:
RANDOM_DELAY=360
0 0 * * * root /opt/nginx-geo/nginx-geo- Add the following to
/etc/nginx/nginx.conf:
geo $remote_addr $geoip_country_code {
include /etc/nginx/include/geoip_country_code.conf;
}
map $geoip_country_code $geoip_country_name {
include /etc/nginx/include/geoip_country_name.conf;
}
proxy_set_header GeoIP-Country-Code $geoip_country_code;
proxy_set_header GeoIP-Country-Name $geoip_country_name;