Nginx地区访问限制
- 首先我们得添加该服务所需要的第三方库
找到我们编译安装nginx包所在位置
[root@ayi ayi]# ls
nginx-1.21.1 nginx-1.21.1.tar.gz
[root@ayi ayi]# pwd
/ayi
- 添加所需要的的库
[root@ayi nginx-1.21.1]# pwd
/ayi/nginx-1.21.1
[root@ayi nginx-1.21.1]# ./configure --add-module= --with-http_geoip_module
-
ok,现在已经添加完了我们所需要的库了。下载一下,解压
(这里因为社区里存在该资源了,有朋友需要的话可以私聊我) -
解压,并将GeoIP.dat GeoLiteCountry.dat GeoLiteCity.dat 放入我们conf配置目录下
cp GeoIP.dat GeoLiteCountry.dat GeoLiteCity.dat /usr/local/ayi/conf/
- 随后我们在conf目录下编辑nginx.conf
#tcp_nopush on;
geoip_country /usr/local/ayi/conf/GeoIP.dat;
geoip_city /usr/local/ayi/conf/GeoLiteCity.dat;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name www.ayi.com;
if ($geoip_city != 'Hengyang' ){ #这里就是除了衡阳以外的都被限制不能访问了
return 403;
}
if ($geoip_country_code != 'CN' ){
return 404;
}
#charset koi8-r;
总结:NGINX还有很多模块等我们去摸索,共勉。(需要资源的私聊我哈)