gpt4 book ai didi

nginx - 如何授予对 nGinx 中被 GeoIP [国家] 阻止的特定 IP 地址的访问权限?

转载 作者:行者123 更新时间:2023-12-01 09:57:43 28 4
gpt4 key购买 nike

找不到如何解决这个问题的解决方案。 Here这就是我如何阻止对该国家的访问,同时我需要访问来自被阻止国家的特定 IP。

最佳答案

终于找到了这个问题的解决方案。

1)在nginx.conf中添加

http {

geoip_country /usr/share/GeoIP/GeoIP.dat;

map $geoip_country_code $allowed_country {
default no;
LV yes; # in my case it is Latvia (allowed country, but all other are not)
}

geo $exclusions {

default 0;

123.123.123.123 1; # here comes allowed IP that is in blocked country list

}

}

2) 在您的虚拟主机配置服务器{}容器中

if ($allowed_country = yes) {
set $exclusions 1;
}


if ($exclusions = "0") {
return 403;
}

主要思想来自HERE

关于nginx - 如何授予对 nGinx 中被 GeoIP [国家] 阻止的特定 IP 地址的访问权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17223360/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com