首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

用Nginx禁止国外IP访问我的网站...

图片来自 Pexels 想要实现这个功能有很多方法,下面我就来介绍基于 Nginx 的 ngx_http_geoip2 模块来禁止国外 IP 访问网站。 ①安装 geoip2 扩展依赖: [root@fxkj ~]# yum install libmaxminddb-devel -y ②下载 ngx_http_geoip2_module 模块: [root@fxkj tmp]# git clone https://github.com/leev/ngx_http_geoip2_module.git [ro tmp]# ③解压模块到指定路径 我这里解压到 /usr/local 目录下: [root@fxkj tmp]# mv ngx_http_geoip2_module/ /usr/local/ [root@fxkj local]# ll ngx_http_geoip2_module/ total 60 -rw-r--r-- 1 root root 1199 Aug 13 17:20 config -rw-r--r-- 1 root root 1311 Aug 13 17:20 LICENSE -rw-r--r-- 1 root root 23525 Aug 13 17:20 ngx_http_geoip2_module.c -rw-r--r-- 1 root root 21029 Aug 13 17:20 ngx_stream_geoip2_module.c -rw-r--r-- 1 root root 3640 Aug 13 17:20 README.md ④安装 nginx 模块 首先说明下环境,我的 nginx 版本是 1.16,在网上查了下安装 ngx_http_geoip2 模块至少需要 1.18 版本及以上,因此此次安装我是升级 nginx1.18,添加 ngx_http_geoip2 模块。 下载 nginx 1.18 版本: [root@fxkj ~]# yum install libmaxminddb-devel -y 解压 nginx1.18 软件包,并升级为 nginx1.18,添加 ngx_http_geoip2 模块。 需要注意:

02
领券