nginx:使用带有允许/拒绝指令的 geo 模块

Iva*_*van 4 nginx

阅读 nginx 的ngx_http_access_module文档,我发现了这一点:

如果规则很多,最好使用ngx_http_geo_module模块变量。

如何使用 geo 模块允许/拒绝?如果我这样做:

geo $listofips {
    default 0;
    8.8.8.8 1;
}

server {
    # [...]
    allow $listofips;
    deny all;
}
Run Code Online (Sandbox Code Playgroud)

它给了我以下错误:

/path/to/config:97 中的参数“$listofips”无效

如何使用 geo 模块进行访问控制?我无法使用 ifs,因为它显然会损坏try_files(请参阅 nginx 的 IfIsEvil)。

小智 5

如果不使用 IF 我确信在编写此答案时这是不可能的。

所以在这种情况下看起来像这样:

geo $trusted_user {
    default 0;
    8.8.8.8 1;
}

server
{
    if ( $trusted_user = 0 ) {
        return 403;
    }
}
Run Code Online (Sandbox Code Playgroud)

向 NGINX 团队发送建议: https: //www.nginx.com/

这个问题是根据以下回复回答的:NGINX - 有条件地允许或拒绝 IP

“示例”中搜索源“# try_files wont work due to if ” : https: //www.nginx.com/resources/wiki/start/topics/depth/ifisevil/#examples