更新 *2: 在 Surge 4.0.2 (Build 1462) 商店版中,此问题已被解决,本文失效。

更新: 根据 @XYen0n 大佬的 提醒,如果你不想注册 GeoLite2 账户,那么请直接使用本文 最后 的方法。


背景及需求

根据 MaxMind 官方 公告,从 2019 年 12 月 30 日起,用户需要注册 MaxMind 账户并使用 license key 才能下载免费的 GeoLite2 数据库,原公开下载链接也不再可用。原文:

Starting December 30, 2019, we will be requiring users of our GeoLite2 databases to register for a MaxMind account and obtain a license key in order to download GeoLite2 databases.

Starting December 30, 2019, downloads will no longer be served from our public GeoLite2 page, from geolite.maxmind.com/download/geoip/database/*, or from any other public URL.

由于 Surge 使用了公开的 GeoLite2 Country 下载链接,它暂时将无法更新 GeoIP 数据库。不过,既然官方提供了注册账户 & 使用 license key 下载的方式,我们仍然可以曲线救国。

注册 GeoLite2 账户

打开 GeoLite2 Sign Up 页面,按要求填写个人信息即可。对于邮箱地址,官方的要求是:

Please provide an email address using the domain name of your business. This will become your username.

如果你用 Gmail 之类的邮箱可能会提示 Sorry, we are not able to provide you with an account. 反正咱用的是自己的域名邮箱注册的。最后别忘了验证邮箱并设置密码。

如果你不想折腾,买一个域名然后开通免费的 QQ 域名邮箱 就行了。QQ 域名邮箱不让用了,有需要的可以用免费版 腾讯企业邮箱 或者垃圾 Yandex

获取 License key

注册好账户之后,打开管理 license keys 的 页面,点 Generate new license key,description 随便填写,Will this key be used for GeoIP Update? 选择 No 即可。记录下你最终获得的 license key。

配置 Surge

MitM

在 Surge 配置文件的 [MITM] > hostname 部分,增加以下域名:

geolite.maxmind.com

Rewrite

在 Surge 配置文件的 [URL Rewrite] 部分,增加一行:

^https:\/\/geolite\.maxmind\.com\/download\/geoip\/database\/GeoLite2-Country\.tar\.gz https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key=<你获得的license key>&suffix=tar.gz 302

记得把中间 license_key= 后的内容改为你获得的 license key。

直接使用 rixCloud 提供的 GeoIP 数据库

如果你懒得注册 GeoLite2 账户,那么不妨直接使用 rixCloud 提供的 GeoIP 数据库:

MitM

在 Surge 配置文件的 [MITM] > hostname 部分,增加以下域名:

geolite.maxmind.com

Rewrite

在 Surge 配置文件的 [URL Rewrite] 部分,增加一行:

^https:\/\/geolite\.maxmind\.com\/download\/geoip\/database\/GeoLite2-Country\.tar\.gz https://static.clash.to/GeoIP2/GeoIP2-Country.tar.gz 302

Enjoy!


参考