Nginx GeoIP2 module
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)
The module now supports nginx streams and can be used in the same way the http module can be used.
First install libmaxminddb as described in its README.md file.
wget http://nginx.org/download/nginx-VERSION.tar.gz
tar zxvf nginx-VERSION.tar.gz
cd nginx-VERSION./configure --with-compat --add-dynamic-module=/path/to/ngx_http_geoip2_module
make modulesThis will produce objs/ngx_http_geoip2_module.so. It can be copied to your nginx module path manually if you wish.
Add the following line to your nginx.conf:
load_module modules/ngx_http_geoip2_module.so;./configure --add-module=/path/to/ngx_http_geoip2_module
make
make install./configure --add-dynamic-module=/path/to/ngx_http_geoip2_module --with-stream
OR
./configure --add-module=/path/to/ngx_http_geoip2_module --with-streamThe free GeoLite2 databases are available from Maxminds website (requires signing up)
…Retrieve metadata regarding the geoip database.
$variable_name metadata Available fields:
Enabling auto reload will have nginx check the modification time of the database at the specified interval and reload it if it has changed.
auto_reload $variable_name [default=
"iso_code":
"US"
"names":
{
"de":
"USA"
"en":
"United States"
}
}
}
$ mmdblookup --file /usr/share/GeoIP/GeoIP2-Country.mmdb --ip 8.8.8.8 country names en
"United States" This translates to:
$country_name "default=United States" source=$remote_addr country names enThese commands works the same as the original ngx_http_geoip_module documented here: http://nginx.org/en/docs/http/ngx_http_geoip_module.html#geoip_proxy.
However, if you provide the source=$variable_with_ip option on a variable, these settings will be ignored for that particular variable.
geoip2_proxy Defines trusted addresses. When a request comes from a trusted address, an address from the "X-Forwarded-For" request header field will be used instead.
geoip2_proxy_recursive If recursive search is disabled then instead of the original client address that matches one of the trusted addresses, the last address sent in "X-Forwarded-For" will be used. If recursive search is enabled then instead of the original client address that matches one of the trusted addresses, the last non-trusted address sent in "X-Forwarded-For" will be used.
No open issues yet, or sync has not completed.