Nginx地理封锁&允许局域网IP

我想阻止除了列入白名单的国家和局域网之外的地理区域IP。 第一部分完美无瑕,第二部分完美无瑕。 Somweheresearch互联网我发现代码LH(本地主机)和LN(本地networking),但他们都不工作。

我正在使用标准的代码阻止。

nginx.conf中的相关http {}部分:

geoip_country /usr/share/GeoIP/GeoIP.dat; map $geoip_country_code $allowed_country { default no; US yes; } 

站点中的相关服务器{}部分可用/默认:

 block countries if ($allowed_country = no) { return 444; } 

我们欢迎所有的build议!

更新:

$ geoip_country_codevariables在LAN IP访问上返回“ – ”,但添加“ – yes;” 到geoip_county块也不起作用。

我find了一个解决scheme – 不知道它是否“干净”。 只要覆盖了$ allowed_countryvariables,前提是LAN IP条件匹配。

geo $ lan-ip {
默认没有;
192.168.1.0/24是;
}

而这个块之前的“#block国家”部分

如果($ lan-ip = yes){
设置$ allowed_country yes;
}