geoip_module模块

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/m0_38004619/article/details/79096957

geoip_module模块

一、基于IP地址匹配MaxMind GeoIP二进制文件,读取IP所在地域信息。

二、geoip_module使用场景

1.区别国内外作为HTTP访问规则。

2.区别国内城市地域作HTTP访问规则。

三、实例步骤:

1.yum install nginx-module-geoip

2.nginx配置文件加载 

3.下载地域ip文件

maxmind 提供的免费版数据库已经可以满足需求,在使用数据库前,需要先编译 GeoIP 组件:
wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP-1.4.8.tar.gz

./configure
make
make install

4.nginx配置文件读取地域文件

geoip_country /etc/nginx/geoip/GeoIP.dat;
geoip_city /etc/nginx/geoip/GeoLiteCity.dat;


5. 配置如下

location / {
if ($geoip_country_code != CN) { #禁止中国访问
return 403;
}
root   /usr/share/nginx/html;
index  index.html index.htm;
}

猜你喜欢

转载自blog.csdn.net/m0_38004619/article/details/79096957