nginx安装限制国外或者省—geoip2
#安装依赖库
yum install libmaxminddb-devel -y
- 1
进去宝塔的脚本目录
cd /www/server/panel/install
- 1
读修改宝塔官方写的脚本
vim nginx.sh
- 1
找到字符 ./configure - 添加模块
--add-module=/usr/share/GeoIP/ngx_http_geoip2_module
- 1
更新nginx以及添加模块
必须要在/www/server/panel/install 找到nginx.sh 执行以下命令
sh nginx.sh update 1.20 (1.20为nginx的版本号)
- 1
更新完后查看echo模块是否存在
nginx -V
- 1
完成后配置nginx (限制国外默认yes CN中国 no)
geoip2 /usr/share/GeoIP/GeoLite2-City.mmdb {
auto_reload 5m;
$geoip2_data_country_code country iso_code;
$geoip2_data_region_code subdivisions 0 iso_code;
$geoip2_data_region_name subdivisions 0 names en;
}
map $geoip2_data_country_code $allowed_country {
default yes;
CN no;
}
map $geoip2_data_region_name $allowed_region {
default yes;
Sichuan no;
}
if ($allowed_country = yes) {
return 404;
}
if ($allowed_region = no) {
return 404;
}
本文共 个字数,平均阅读时长 ≈ 分钟,您已阅读:0时0分0秒。
649494848