找不到解决方案如何解决这个问题. 以下是我阻止访问该国家/地区的方式,同时我需要访问来自被阻止国家/地区的特定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
}
}
Run Code Online (Sandbox Code Playgroud)
2)在您的vhost配置服务器{}容器中
if ($allowed_country = yes) {
set $exclusions 1;
}
if ($exclusions = "0") {
return 403;
}
Run Code Online (Sandbox Code Playgroud)
主要想法来自HERE
| 归档时间: |
|
| 查看次数: |
4470 次 |
| 最近记录: |