http-geoip2 #
Puts the country, city or other GeoIP2 data for a client IP address into nginx variables. Use it to log locations, to block or redirect by country, or to pass the location to the backend. It reads MaxMind databases and works for HTTP and stream.
Source: upstream source
Directives
geoip2 #
syntax: geoip2 1 arg; · context: http
Defines a GeoIP2 database path and maps looked-up geographic fields to nginx variables based on the client or a specified IP.
geoip2_proxy #
syntax: geoip2_proxy 1 arg; · context: http
Specifies trusted proxy CIDR ranges whose X-Forwarded-For header value is used for GeoIP2 lookups instead of the direct client address.
geoip2_proxy_recursive #
syntax: geoip2_proxy_recursive on | off (on/off flag); · context: http
Boolean directive — set to "on" or "off".
Example
http {
...
geoip2 /etc/maxmind-country.mmdb {
auto_reload 5m;
$geoip2_metadata_country_build metadata build_epoch;
$geoip2_data_country_code default=US source=$variable_with_ip country iso_code;
$geoip2_data_country_name country names en;
}
geoip2 /etc/maxmind-city.mmdb {
$geoip2_data_city_name default=London city names en;
}
....
fastcgi_param COUNTRY_CODE $geoip2_data_country_code;
fastcgi_param COUNTRY_NAME $geoip2_data_country_name;
fastcgi_param CITY_NAME $geoip2_data_city_name;
....
}
stream {
...
geoip2 /etc/maxmind-country.mmdb {
$geoip2_data_country_code default=US source=$remote_addr country iso_code;
}
...
}