Skip to content

Repository files navigation

nginx-geo (version 2.1.1)

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.

Installation

Important

Python 3.9+ and the requests module are required.

  • Clone this repository into the /opt/nginx-geo directory:
cd /opt && git clone https://github.com/makhomed/nginx-geo.git nginx-geo
  • Create the nginx-geo.toml configuration 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

Usage

  • Create the /etc/cron.d/nginx-geo file 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;

About

This tool сonverts the MaxMind GeoLite2 Country database into files suitable for use with the nginx geo module.

Topics

Resources

Stars

7 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages