.
3ss.cn

nginx的GeoIP有什样用

Nginx中自带GeoIP模块可以屏蔽指定IP的请求,只不过默认没有被编译,打开以后我们只要再下载一个IP规则就行,Nginx服务器中配置GeoIP模块来拦截指定国家IP。 ( 推荐学习:nginx使用 )

最近有一个网站项目需求:需要屏蔽国内的方问请求。花时间研究了一下这方面的资料。目前找到的最佳方法就是使用 Nginx 的 GeoIP 模块来实现地区的识别。然后配置相关国家的 ISO 名称,禁止访问即可。记录一下相关过程。

编译 GeoIP 组件

maxmind 提供的免费版数据库已经可以满足需求,在使用数据库前,需要先编译 GeoIP 组件:

wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP-1.4.8.tar.gz
./configure
make
make install

下载 IP 库

从 maxmind 下载 IP 数据包并解压。 这个是国家的ip数据包:

wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
gunzip GeoIP.dat.gz

这个是城市的ip数据包:

wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
gunzip GeoLiteCity.dat.gz

执行完上面的命令后,会得到 GeoIP.dat 和 GeoLiteCity.dat 文件。将这两个文件复制到 Nginx 的 conf 目录。

赞(0)
未经允许不得转载:互联学术 » nginx的GeoIP有什样用

评论 抢沙发