MAXMIND GeoLite2 ip地址数据库,更新时间2023-03-07,可结合nginx的geoip2模块实现用户的访问地区控制
GeoLite2 数据库是免费的 IP 地理定位数据库,与MaxMind 的 GeoIP2 数据库相当,但准确性较低 。GeoLite2 国家、城市和 ASN 数据库 每周更新两次,即每周二和周五。
官方网站:geoip2-services-and-databases
nginx规则示例: nginx要支持geoip2模块才可以使用
http{
···
# 国家缩写
geoip2 /blog-data/nginx/geoip2/GeoLite2-Country.mmdb {
$geoip2_country_code country iso_code;
}
# 城市地区
geoip2 /blog-data/nginx/geoip2/GeoLite2-City.mmdb {
$geoip2_city_names location time_zone;
}
# 设置国家规则
map $geoip2_country_code $allowed_country {
# 默认拒绝所有
default no;
# 中国允许
CN yes;
}
# 设置地区规则
map $geoip2_city_names $allowed_city {
default no;
Asia/Shanghai yes;
}
···
server {
···
# 添加响应头显示ip(方便查看)
add_header client-country $geoip2_country_code;
add_header client-city $geoip2_city_names;
# 匹配地区规则类型为no的,返回404
if ( $allowed_city = no ) {
return 404;
}
# 匹配国家类型为no的,返回404
#if ( $allowed_country = no ) {
return 404;
}
···
}#server 结束
}#http 结束
数据库文件下载(蓝奏网盘): GeoLite2-City.mmdb | GeoLite2-Country.mmdb | 点我显示密码
本站文章除注明[转载|引用|原文]出处外,均为本站原生内容,转载前请注明出处 | 文章链接地址:https://me.jinchuang.org/archives/1329.html