|
  
TA的每日心情 | 擦汗 2 小时前 |
|---|
签到天数: 1685 天 [LV.Master]伴坛终老
|
先说明下libmaxminddb、ngx_http_geoip2_module、nginx之间的关系
libmaxminddb 是底层基础库,ngx_http_geoip2_module 是Nginx的扩展模块,而 geo 则是Nginx内置但功能不同的另一个模块。简单来说,ngx_http_geoip2_module 依赖 libmaxminddb 来读取数据库,而它与 geo 模块是两个独立的方案
到https://github.com/maxmind/libmaxminddb、https://github.com/leev/ngx_http_geoip2_module下载压缩包
解压两个压缩包,到libmaxminddb目录里面执行编译安装
[root@localhost libmaxminddb-1.13.3]# ./configure
[root@localhost libmaxminddb-1.13.3]# make
[root@localhost libmaxminddb-1.13.3]# make install
[root@localhost libmaxminddb-1.13.3]# echo /usr/local/lib >> /etc/ld.so.conf.d/local.conf
[root@localhost libmaxminddb-1.13.3]# ldconfig
[root@localhost nginx-1.26.0]# ./configure --add-module=/usr/local/src/ngx_http_geoip2_module-3.4
下载IP数据库,分三类:country、ASN、City,官网下载:maxmind.com,城市的应该限制地域,不允许下载
编辑nginx配置文件,增加如下内容调试
geoip2 ./GeoLite2-Country_20260703/GeoLite2-Country.mmdb {
$geoip2_country_code country iso_code;
}
geoip2 ./GeoLite2-ASN_20260706/GeoLite2-ASN.mmdb {
$geoip2_asn_code autonomous_system_number;
}
geoip2 ./GeoLite2-City_20230519/GeoLite2-City.mmdb {
$geoip2_country_code country iso_code;
$geoip2_province_name subdivisions 0 iso_code;
$geoip2_city_name city names en;
}
add_header city $geoip2_city_name;
add_header country $geoip2_country_code;
add_header province $geoip2_province_name;
add_header asn $geoip2_asn_code;
重新加载配置文件:nginx -s reload
访问网站,看下响应头是否有country 、province 、city 、asn ,有则代表生效了
|
|