Regular nginx installation geoip2 module can also refer to this article.Just pay attention to the * in the article.
Because nginx is already installed through the panel, We ignore the introduction of Nginx Install and some basic settings.
Download the GeoLite2 mmdb:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#Update.2020-03 Below are permalinks that you can use to download the database. You must register an Maxmind account first. Remember to replace YOUR_LICENSE_KEY. # GeoLite2-City Database URL https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=YOUR_LICENSE_KEY&suffix=tar.gz # GeoLite2-City SHA256 URL https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=YOUR_LICENSE_KEY&suffix=tar.gz.sha256 # GeoLite2-Country Database URL https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key=YOUR_LICENSE_KEY&suffix=tar.gz # GeoLite2-Country SHA256 URL https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key=YOUR_LICENSE_KEY&suffix=tar.gz.sha256 |
1 2 3 4 5 6 7 8 9 10 11 12 |
#Update.2020-03 cd /usr/share/GeoIP/ tar zxvf GeoLite2-Country_20200303.tar.gz tar zxvf GeoLite2-City_20200303.tar.gz mv GeoLite2-Country_20200303/GeoLite2-Country.mmdb GeoLite2-Country.mmdb mv GeoLite2-City_20200303/GeoLite2-City.mmdb GeoLite2-City.mmdb #"_20200303" Please change the file name according to the file you downloaded #below's the old one cd /usr/share/GeoIP/;wget http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz;gunzip GeoLite2-City.mmdb.gz;wget http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.mmdb.gz;gunzip GeoLite2-Country.mmdb.gz |
Install libmaxminddb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
cd /usr/local/src git clone --recursive https://github.com/maxmind/libmaxminddb cd libmaxminddb ./bootstrap ./configure make make install sh -c "echo /usr/local/lib >> /etc/ld.so.conf.d/local.conf" ldconfig |
Install the ngx_http_geoip2_module *
* “/www/server/nginx/src” is my module directory in the BaoTa. You can change it to your own directory.
1 2 |
cd /www/server/nginx/src git clone --recursive https://github.com/leev/ngx_http_geoip2_module |
Before configure, you may need use ‘nginx – V’ to check out the Nginx’s original build parameters.
1 2 3 |
./configure --user=www --group=www --prefix=/www/server/nginx --with-openssl=/www/server/nginx/src/openssl --add-module=/www/server/nginx/src/ngx_devel_kit --add-module=/www/server/nginx/src/lua_nginx_module --add-module=/www/server/nginx/src/ngx_cache_purge --add-module=/www/server/nginx/src/nginx-sticky-module --add-module=/www/server/nginx/src/nginx-http-concat --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_gunzip_module --with-stream --with-stream_ssl_module --with-ipv6 --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_mp4_module --with-ld-opt=-Wl,-E --with-pcre=pcre-8.40 --with-ld-opt=-ljemalloc --add-module=/www/server/nginx/src/ngx_http_geoip2_module make make install |
ngx_http_geoip2_module Configuration
Nginx Conf
The # is the original example of ngx_http_geoip2_module github
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
http{ ... geoip2 /usr/share/GeoIP/GeoLite2-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_code default=US country iso_code; $geoip2_data_country_name country names en; } geoip2 /usr/share/GeoIP/GeoLite2-City.mmdb { $geoip2_data_city_name default=London city names en; } ... |
Temporarily come to an end.
Some useful links :
ngx_http_geoip2_module – github
This article was first published by V on 2019-02-01 and can be reprinted with permission, but please be sure to indicate the original link address of the article :http://www.nginxer.com/records/how-to-install-the-geoip2-module-for-nginx-on-the-baota-panel/
1 Comment
now download need to add access code.
use:
https://download.maxmind.com/app/geoip_download_by_token?edition_id=GeoLite2-Country&license_key={LICENSE KEY HERE}&suffix=mmdb.gz