http-geoip2 #
ngx_http_geoip2_module - creates variables with values from the maxmind geoip2 databases based on the client IP (default) or from a specific variable (supports both IPv4 and IPv6)
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;
}
...
}