雷池的地域功能是付费的,但可以在加一个nginx用来过滤非大陆地址然后将正常国内流量转发给雷池。
功能依赖Nginx模块geoip2 先安装(现在正常发行版直接用包管理即可安装无需编译)
1 2
| apt install nginx libnginx-mod-http-geoip2
|
下载IP属地数据文件
https://www.maxmind.com/
选免费注册 然后登录下载

解压出mmdb文件,Nginx 配置geoip2
http{}
内配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| geoip2 /etc/nginx/GeoLite2/GeoLite2-Country.mmdb {
auto_reload 5m; $geoip2_data_country_code country iso_code; }
map $geoip2_data_country_code $allowed_country { default yes; CN no; HK no; TW no; }
|
server{}
内配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| location / {
if ($allowed_country = yes) { return 403; }
proxy_pass http://10.0.0.10;
proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }
|
大功告成。