gpt4 book ai didi

varnish - 我可以在 Varnish 4 中创建类似于 ACL 的自定义值列表吗?

转载 作者:行者123 更新时间:2023-12-02 14:50:01 25 4
gpt4 key购买 nike

我正在使用 Varnish 版本 4。我想知道 VCL 是否允许自定义且可重用的值列表,如 ACL。我想用它来检查访客的 cookie。如果他是版主,请勿提供缓存内容。

Cookie 字符串:

   session=9urt2jipvkq77brfrf; UserID=158

代码:

   acl moderator{
"158";
"114";
}

sub vcl_recv {

set req.http.UserID = regsub(req.http.Cookie,".*UserID=(\d+).*","\1"); // 158

if(req.http.UserID ~ moderator){ // 158 found in the moderator list

return(pass);
}
}

最佳答案

简短回答:否

ACL(访问控制列表)仅用于指定不同的IP/主机。

但是您可以使用 VMOD 来完成此操作。结账Variable

它有一些设置和获取变量的基本函数。

set("my_var", "this is the value")
set req.http.x-my-var = get("my_var")

还有一些更高级的功能,例如使用正则表达式从单个字符串设置多个变量。

variable.regset("ttl:d=\1s,grace:d=\2s", "^(?:.*,)?max-age=([0-9]+)(?:+([0-9]+))", beresp.http.Surrogate-Control);
set beresp.ttl = variable.get_duration("ttl");
set beresp.grace = variable.get_duration("grace");

ttl 是变量的名称,grace 是第二个变量的名称

\1\2 是对正则表达式的简单反向引用

:d 指定类型,在本例中为duration

您的用户 ID 列表:s

您可以将它们设置为逗号分隔的字符串

set("moderators", ",158,114,") //Notice the starting and ending comma-sign

if(","+req.http.UserID+"," ~ get("moderators")){

return(pass);
}

关于varnish - 我可以在 Varnish 4 中创建类似于 ACL 的自定义值列表吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34389677/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com