音乐分享(自动连播):
So cold
Not my baby
Wicked Game
What Is Love
Once Upon a Time
The Heart Of The Ocean
靳闯博客 记录是一种习惯 、分享是一种态度
MAXMIND 免费的GeoLite2数据库分享
发表于 - | 分类 - 技术积累 | 标签 - Nginx Geoip

MAXMIND GeoLite2 ip地址数据库,更新时间2023-03-07,可结合nginx的geoip2模块实现用户的访问地区控制
GeoLite2 数据库是免费的 IP 地理定位数据库,与MaxMind 的 GeoIP2 数据库相当,但准确性较低 。GeoLite2 国家、城市和 ASN 数据库 每周更新两次,即每周二和周五。

官方网站:geoip2-services-and-databases

maxmindgeoip2.png

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

如果这篇文章帮助到了你,我感到十分荣幸!

记录 🐾 分享 👣 进步 💪 变强


留言

顶部