wget https://github.com/maxmind/libmaxminddb/releases/download/1.3.2/libmaxminddb-1.3.2.tar.gz tar -zxvf libmaxminddb-1.3.2.tar.gz cd libmaxminddb-1.3.2 ./configure && make && make install echo /usr/local/lib >> /etc/ld.so.conf.d/local.conf ldconfig cd ..
wget http://nginx.org/download/nginx-1.18.0.tar.gz tar -xvf nginx-1.18.0.tar.gz cd nginx-1.18.0 ./configure --add-module=<ngx_http_geoip2_module> make && make install /usr/local/nginx/sbin/nginx -V cd ..
配置Nginx
/usr/local/nginx/conf/nginx.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
http {
geoip2 /usr/share/GeoIP/GeoLite2-Country.mmdb { $geoip2_country_code country iso_code; } server { listen 80;
location / { add_header Country $geoip2_country_code; root /usr/share/nginx; index index.html; } }