gpt4 book ai didi

varnish - 无法在其他导演中使用Varnish导演

转载 作者:行者123 更新时间:2023-12-03 17:46:00 25 4
gpt4 key购买 nike

我正在尝试嵌套Varnish Director,但尽管在多个地方都提到过,但它在4.1.10或6.4中不起作用。
我有两个随机导演,我想将它们添加到后备导演中,如下所示:

vcl 4.0;

import directors;
backend alpha { .host = "192.168.0.101"; }
backend bravo { .host = "192.168.0.102"; }

sub vcl_init {
new primary_director = directors.random();
primary_director.add_backend(alpha, 1.0);

new secondary_director = directors.random();
secondary_director.add_backend(bravo, 1.0);

new fallback_director = directors.fallback();
fallback_director.add_backend(primary_director);
fallback_director.add_backend(secondary_director);
}
official documentation支持这种情况:

Note that directors can use other directors as backends


知道我在这里做错了什么吗?
您可以通过将上面的代码段另存为 /tmp/test.vcl并在Docker中运行 Varnish 来自己进行测试:
$ docker run -v /tmp/test.vcl:/test.vcl --rm varnish:6.4 varnishd -F -f /test.vcl
Error:
Message from VCC-compiler:
Expression has type INSTANCE, expected BACKEND
('/test.vcl' Line 15 Pos 35) -- (Pos 50)
fallback_director.add_backend(primary_director);
----------------------------------################--

Expected argument: BACKEND (unnamed argument)

While compiling function call:

('/test.vcl' Line 15 Pos 5) -- (Pos 50)
fallback_director.add_backend(primary_director);
----##############################################--

Running VCC-compiler failed, exited with 2
VCL compilation failed

最佳答案

非常感谢Varnish IRC董事会的成员-他们使我迅速得到了答案!
这是我的示例的更正版本:

vcl 4.0;

import directors;
backend alpha { .host = "192.168.0.101"; }
backend bravo { .host = "192.168.0.102"; }

sub vcl_init {
new primary_director = directors.random();
primary_director.add_backend(alpha, 1.0);

new secondary_director = directors.random();
secondary_director.add_backend(bravo, 1.0);

new fallback_director = directors.fallback();
fallback_director.add_backend(primary_director.backend());
fallback_director.add_backend(secondary_director.backend());
}

sub vcl_recv {
set req.backend_hint = fallback_director.backend();
}
这里的关键点是:
  • 正确的语法是fallback_director.add_backend(primary_director.backend());
  • 如果没有set req.backend_hint = fallback_director.backend();,Varnish将使用定义的第一个后端。
  • 关于varnish - 无法在其他导演中使用Varnish导演,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62882300/

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