nginx安装限制国外或者省---geoip2

nginx安装限制国外或者省—geoip2

#安装依赖库

yum install libmaxminddb-devel -y

进去宝塔的脚本目录

cd /www/server/panel/install

读修改宝塔官方写的脚本

vim nginx.sh

找到字符 ./configure - 添加模块

--add-module=/usr/share/GeoIP/ngx_http_geoip2_module

更新nginx以及添加模块

必须要在/www/server/panel/install 找到nginx.sh 执行以下命令

sh nginx.sh update 1.201.20为nginx的版本号)

更新完后查看echo模块是否存在

nginx -V

完成后配置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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值