Skip to content

Latest commit

 

History

History
51 lines (33 loc) · 1.71 KB

File metadata and controls

51 lines (33 loc) · 1.71 KB

nginx-geo (version 2.1.0)

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;