1.安装geoip2扩展依赖
yum install libmaxminddb-devel -y2.下载ngx_http_geoip2_module模块
https://github.com/leev/ngx_http_geoip2_module.git3.编译安装
./configure --add-module=/datasdb/ngx_http_geoip2_module-3.44.下载最新数据库文件
模块安装成功后,还要在 Nginx 里指定数据库,在安装运行库时默认安装了两个,位于 /usr/share/GeoIP/ 目录下,一个只有 IPv4,一个包含 IPv4 和 IPv6
这里咱们通过登录www.maxmind.com下载最新的数据库文件

5.配置nginx

     geoip2 /usr/share/GeoIP/GeoLite2-City.mmdb {
         auto_reload 5m;
         $geoip2_data_country_code country iso_code;
     }
     map $geoip2_data_country_code $allowed_country {
         default yes;
         CN no;
     }     if ($allowed_country = yes) { 
         return 403;
     }


















