声明新变量(例如map
geoIP2 或 geoIP2)总是在http
上下文中。
假设我只需要在配置中的某个location
块上检查 ip 的位置,这是否意味着与 geoIP2 相关的这些变量将在与服务器建立的任何连接中或仅在其被调用时计算?
我想知道 NGINX 是如何工作的,什么时候计算变量?
例子:
http{
geoip2 GeoIP/GeoLite2-Country.mmdb {
$geoip2Country country iso_code;
}
map $geoip2Country $denyCountry {
default 1;
US 0;
}
location /zone/{ //the only location where I use the variable
if ($denyCountry){
return 444;
}
}
}