安装 GeoIP2 依赖
https://github.com/maxmind/libmaxminddb
tar -zxvf libmaxminddb.tar.gz
cd libmaxminddb-1.3.2
./configure && make && make install
echo /usr/local/lib >> /etc/ld.so.conf.d/local.conf
ldconfig
下载IP库
https://www.maxmind.com/en/accounts/562897/geoip/downloads
编译模块
https://github.com/leev/ngx_http_geoip2_module
./configure --prefix=/opt/nginx --add-module=/root/ngx_http_geoip2_module-master
配置
geoip2 /opt/nginx/GeoLite2-Country.mmdb {
$geoip_country_code default=- source=$http_x_forwarded_for country iso_code;
$geoip_country_name country names en;
}
geoip2 /opt/nginx/GeoLite2-City.mmdb {
$geoip_city_name default=- city names en;
}