nginx使用geoip做区域限制
GeoIP过滤器根据来自Maxmind GeoLite2数据库的数据添加有关IP地址的地理位置的信息。
通过IP区别国内或国外,从而跳转到不同的页面,最终用nginx的第三方module:geoip来实现,这就不说它的优势了,网上很多解释,下面看怎么配置 ( 推荐学习:nginx使用 )
我的系统中是配置了nignx.repo的,我直接用yum来安装了geoip模块,没有用添加模块重编的方式
yum install nginx-module-geoip
下载geoip的数据库文件
cd /etc/nginx
mkdir geoipdat
cd geoipdat
下载
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
解压
gunzip GeoIP.dat.gz
gunzip GeoLiteCity.dat.gz
根据需求配置nginx
首先在nginx.conf中加载geoip的库,配置如下:

配置虚拟主机如下:

opt目录如下
