Debian系统宝塔nginx配置geoip2屏蔽现判断国家IP跳转

Debian 12系统如何屏蔽国家IP,按顺序操作
一,安装geoip2依赖扩展

sudo apt install libmaxminddb-dev -y

二:下载ngx_http_geoip2_module

git clone https://github.com/leev/ngx_http_geoip2_module.git

三:在宝塔面板里边安装nginx的时候选择编译安装,并手动增加扩展,安装时候点击启用

模块名称  ngx_http_geoip2_module

模块说明  禁用国家ip

模块参数  --add-module=/root/ngx_http_geoip2_module

等待安装后输入  nginx -V 查看是否安装成功

四:上传GeoLite2-Country.mmdb 文件到/www 目录下

配置nginx
在nginx配置文件中,http段加入以下代码。以宝塔安装的nginx为例,打开/www/server/nginx/conf/nginx.conf文件,在http中添加

# 国家代码源

          geoip2 /www/GeoLite2-Country.mmdb {
              $geoip2_data_country_code country iso_code;
          }
          # 映射 MM
          map $geoip2_data_country_code $allowed_country {
            default yes;
            MM no;
            KH no;    
            LA no;
            TH no;
            ID no;
            PH no;
            MY no;
            VN no;
            TL no;
          }



测试网址 https://aibl.vip/ ,网址已经屏蔽了上述国家ip,大家切换ip测试一下
修改 对应站点的配置文件,在/www/server/panel/vhost/nginx 目录中的网站配置文件的server段中添加

if ($allowed_country = no) 
   {
      return 403;
   }


重启nginx,然后根据不同国家ip网络测试即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值