简体   繁体   中英

How install the Geoip2 module on a Nginx running in a production environment?

Can someone explain to me how to install the Geoip2 module on a Nginx 1.14 running in a production environment without breaking the current configuration?

I only find sources indicating how to compile Nginx with the geoip2 module during a first installation.

I am using the Linux distribution Debian 10.

Thank you

First install libmaxminddb libs:

sudo add-apt-repository ppa:maxmind/ppa
sudo apt update
sudo apt install libmaxminddb0 libmaxminddb-dev mmdb-bin

Download and unpack geoip2 module:

https://github.com/leev/ngx_http_geoip2_module/archive/3.3.tar.gz
tar zxvf 3.3.tar.gz

Download nginx source:

wget https://nginx.org/download/nginx-1.14.2.tar.gz
tar zxvf nginx-1.14.2.tar.gz
cd nginx-1.14.2

Then build geoip2 as a dynamic module:

./configure --with-compat --add-dynamic-module=/path/to/ngx_http_geoip2_module
make
make modules

This will produce objs/ngx_http_geoip2_module.so . It can be copied to your nginx module path manually if you wish.

For example:

cp objs/ngx_http_geoip2_module.so /etc/nginx/modules

Obtain latest databases from (need a free registration):

https://dev.maxmind.com/geoip/geoip2/geolite2/#Download_Access

Unpack dtabase files to /usr/share/GeoIP2 directory

Add the following line to your nginx.conf:

load_module modules/ngx_http_geoip2_module.so;

Add to the nginx.conf http section:

geoip2 /usr/share/GeoIP2/GeoLite2-Country.mmdb {
    auto_reload 60m;
    $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 /usr/share/GeoIP2/GeoLite2-City.mmdb {
    auto_reload 60m;
    $geoip2_metadata_city_build metadata build_epoch;
    $geoip2_data_city_name default=London city names en;
}

Then restart Nginx service. Hope that will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM