1. 编译nginx时加ngx_http_geoip2_module, 或者动态加载

load_module /usr/local/libexec/nginx/ngx_http_geoip2_module.so;

  1. 加载geolite2库,http段与国家代码进行map映射:
geoip2 /usr/local/share/GeoIP/GeoLite2-Country.mmdb {
    $geoip2_data_country_code country iso_code;
}
map $geoip2_data_country_code $allowed_country {
    default no;
    CN yes;
}
  1. server或location,负责map条件则拒绝访问
if ($allowed_country = no) {
      return 403;
}

标签: none

添加新评论