[英]How to grant access to a specific IP address that is blocked by GeoIP[country] in nGinx?
Finally found the solution for this problem. 终于找到了解决这个问题的方法。
1) in nginx.conf add 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) in your vhost configuration server{} container 2)在您的vhost配置服务器{}容器中
if ($allowed_country = yes) {
set $exclusions 1;
}
if ($exclusions = "0") {
return 403;
}
In http block 在http块
geoip_country /usr/local/share/GeoIP/GeoIP.dat;
map "$geoip_country_code:$remote_addr" $allowed_country {
default yes;
"~..:10.11.12.13" yes;
"~..:11.12.13.14" no;
"~TR:.*" no;
}
In server block 在服务器块中
if ($allowed_country = no) {
return 403;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.