ngx_http_geoip_module
Client country, city and organization from legacy GeoIP databases
Overview
ngx_http_geoip_module creates variables whose values depend on the client IP address, looked up in the precompiled MaxMind databases of the legacy GeoIP format. A country database yields $geoip_country_code, $geoip_country_code3 and $geoip_country_name; a city database adds region, city, postal code, latitude and longitude variables; an organization database yields $geoip_org.
The module requires the MaxMind GeoIP C library. With IPv6-capable databases (1.3.12, 1.2.7) IPv4 addresses are looked up as IPv4-mapped IPv6 addresses, and geoip_proxy lets requests from trusted addresses use the X-Forwarded-For header instead. MaxMind has discontinued the legacy GeoIP and GeoLite databases, so new deployments should use the GeoIP2 module at /modules/geoip2/ with .mmdb files instead.
It is an official nginx module that upstream does not build by default, so it needs the --with-http_geoip_module configure parameter. The n.wtf packages build it as a dynamic module shipped in libnginx-mod-http-geoip, mainly for existing configurations that still map $geoip_country_code to access rules or log fields.
Key directives
geoip_countryCountry database; provides $geoip_country_code, $geoip_country_code3 and $geoip_country_name. http context.geoip_cityCity database; adds $geoip_city, $geoip_region, $geoip_postal_code, $geoip_latitude and more.geoip_orgOrganization database (1.0.3); exposes $geoip_org with the organization name.geoip_proxyTrusted address or CIDR; for requests from it the address in X-Forwarded-For is used instead.geoip_proxy_recursiveUse the last non-trusted X-Forwarded-For address rather than the last one, default off.Example
Availability
Ships as a dynamic module in libnginx-mod-http-geoip, installed with nginx-extras. The package drops a load_module config into /etc/nginx/modules-enabled/, so it loads on start.