简体   繁体   English

如何授予对nGinx中GeoIP [country]阻止的特定IP地址的访问权限?

[英]How to grant access to a specific IP address that is blocked by GeoIP[country] in nGinx?

Can't find solution how to solve this. 找不到解决方法。 Here is how I blocked an access to the country and at the same time I need to grand access to a specific IP that is from blocked country. 是我阻止对该国家/地区访问的方式,与此同时,我需要对来自该阻止国家/地区的特定IP进行大规模访问。

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;
}

The main idea is from HERE 主要思想是从这里

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM