由于众所周知的原因,国内用户访问站点位置在海外的服务器时,可能会遇到访问速度慢的问题。为了解决这个问题,可以通过Nginx的GeoIP模块实现对国内用户的重定向。
为什么不是CDN?有米我也想用~
GeoIP 模块安装
如果使用的是lnmp一键安装包,可以将 --add-module=/path/to/ngx_http_geoip2_module
放到 lnmp.conf
的 Nginx_Modules_Options=
后方,之后使用 sudo sh upgrade.sh nginx
即可。
GeoIP 数据库
参考:https://dev.maxmind.com/geoip/updating-databases
- 首先我们需要去
https://www.maxmind.com/en/home
注册账号 - 在
https://github.com/maxmind/geoipupdate/releases
下载geoipupdate
工具 - 安装到用户工具目录
sudo cp geoipupdate_5.0.0_linux_amd64/geoipupdate /usr/local/bin
- 创建配置文件
/usr/local/etc/GeoIP.conf
其中 LicenseKey
可以在 https://www.maxmind.com/en/accounts/current/license-key
中找到。