【问题标题】:Varnish won't recognize req.grace variableVarnish 无法识别 req.grace 变量
【发布时间】:2014-06-10 16:11:44
【问题描述】:

我全新安装了 Slackware 64 14 位,并查看了 Varnish installation documentation 我已安装所有依赖项并编译清漆没有错误(make check 通过所有测试)

然而,当我尝试使用 varnish 运行时

varnishd -f /etc/varnish/user.vcl -s malloc,4G -T 127.0.0.1:2000

我明白了

Message from VCC-compiler:
Unknown variable 'req.grace'
At: ('input' Line 17 Pos 9)
    set req.grace = 15s;
--------#########-------

Running VCC-compiler failed, exit 1

VCL compilation failed

我非常简单的/etc/varnish/ucer.vcl 文件如下所示:

vcl 4.0;

# set default backend if no server cluster specified
backend default {
    .host = "127.0.0.1";
    .port = "8080";
    .probe = {
        .url = "/";
        .timeout = 34ms;
        .interval = 1s;
        .window = 10;
        .threshold = 8;
    }
}

sub vcl_recv {
    set req.grace = 15s;
}

sub vcl_fetch {
    set beresp.grace = 30m;
}

变量名与this example相同。

varnishd -V返回

varnishd (varnish-4.0.0 revision 2acedeb)

通过删除 sub vcl_recv 和 sub vcl_fetch(仅使用后端默认值)清漆工作正常,我可以看到它的标题,但我需要编辑 VCL 文件。

有什么想法吗?

【问题讨论】:

    标签: varnish varnish-vcl


    【解决方案1】:

    您正在使用 Varnish 4.0.0,它需要从您的 VCL 代码所基于的 3.0 格式进行更新。

    req.grace 消失了(您通常不需要它)并且 vcl_fetch 现在称为 vcl_backend_response。

    查看升级文档:https://www.varnish-cache.org/docs/trunk/whats-new/upgrading.html

    【讨论】:

    • 谢谢,我不敢相信我错过了。我读了几次关于从 3 升级到 4 的文档,但没有注意到 vlc_fetch 的变化(并且它没有引用恩典,即使我提供的示例使用了这两个术语并且它属于 4.0 文档)。
    【解决方案2】:

    作为参考,可以按照blog post中所说的正确处理宽限功能:

    (复制/粘贴代码,详细请参考博客)

    sub vcl_hit {
        if (obj.ttl >= 0s) {
            # normal hit
            return (deliver);
        }
        # We have no fresh fish. Lets look at the stale ones.
        if (std.healthy(req.backend_hint)) {
            # Backend is healthy. Limit age to 10s.
            if (obj.ttl + 10s > 0s) {
                set req.http.grace = "normal(limited)";
                return (deliver);
            } else {
                # No candidate for grace. Fetch a fresh object.
                return(fetch);
            }
        } else {
            # backend is sick - use full grace
            if (obj.ttl + obj.grace > 0s) {
                set req.http.grace = "full";
                return (deliver);
            } else {
                # no graced object.
                return (fetch);
            }
        }
    }
    

    HTH

    【讨论】:

    • 未来读者请注意:您应该一定阅读全文。
    猜你喜欢
    • 2021-02-27
    • 2013-05-15
    • 1970-01-01
    • 2017-01-04
    • 2013-08-13
    • 2018-11-12
    • 2013-02-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多