• 当前位置: 首 页 > 教育百科 > 学历/技能 > 正文

    基于 NGINX 的来禁止国外 IP 访问网站

    :2025年10月05日
    本站

    下载geoip2模块和数据库,nginx配置实现国家访问控制。

    一、下载geoip2模块

    下载地址:http://github.com/leev/ngx_http_geoip2_module

    二、下载ip地理位置数据库

    http://dev.maxmind.com/geoip/geolite2-free-geolocation-data

    三、nginx.cnf配置使用

    http {

      include mime.types;

      default_type application/octet-stream;

      geoip2 /usr/local/nginx/geoip/GeoLite2-Country.mmdb {

        auto_reload 5m;

        $geoip2_data_country_code country iso_code;

      }

      map $geoip2_data_country_code Sallowed_country (

        default no;

        CN yes;

      }

      server {

        listen 80;

        server_name localhost;

        access_log logs/access.log geoip;

        if ($allowed_country = no){

          return 403;

        }

        location / {

          root html;

          index index.html index.htm;

        }

      }

    }

    [编辑:宋聪乔 &发表于江苏]
    [我要纠错]

    来源:本文内容搜集或转自各大网络平台,并已注明来源、出处,如果转载侵犯您的版权或非授权发布,请联系小编,我们会及时审核处理。
    声明:江苏教育黄页对文中观点保持中立,对所包含内容的准确性、可靠性或者完整性不提供任何明示或暗示的保证,不对文章观点负责,仅作分享之用,文章版权及插图属于原作者。

    关键词: nginx geoip2配置-site access control-ip location blocking-cn
    有价值
    0
    无价值
    0
    猜您喜欢
    最热文章

    暂不支持手机端,请登录电脑端访问

    正在加载验证码......

    请先完成验证