nginx的geoip说明和使用方法:

https://docs.nginx.com/nginx/admin-guide/security-controls/controlling-access-by-geoip/%20

下载geoip2的数据库
注册maxmind后下载数据库文件
然后,访问 Download Files 页面,以下载数据库文件:https://www.maxmind.com/en/accounts/current/geoip/downloads

下载GeoLite2-Country.mmdb和GeoLite2-City.mmdb,并放到/usr/local/nginx/geoip的目录中,并给权

在http段配置

geoip2 /usr/local/nginx/geoip/GeoLite2-Country.mmdb {
auto_reload 10m;
$geoip2_metadata_country_build metadata build_epoch;
$geoip2_data_country_code default=US source=$remote_addr country iso_code;
$geoip2_data_country_name country names en;

虚拟主机段配置,例不允许国内流量来访

if ($geoip_country_code = CN) {
  deny all;
}

只允许国内流量来访

  if ($geoip2_data_country_code != CN) {
            return 200 $geoip2_data_country_code;
        }

在每个虚拟主机的location前加入以上信息,当然你还可以加入location中

分类: nginx使用方法 标签: 暂无标签

评论

暂无评论数据

暂无评论数据

目录