【问题标题】:Varnish 4 ESI: bereq.url doesn't read url inside ESI src tagVarnish 4 ESI:bereq.url 不读取 ESI src 标签内的 url
【发布时间】:2017-09-01 03:26:03
【问题描述】:

我使用 varnish 4、php-fpm 7、nginx、centos 7

我的 varnish.params:

DAEMON_OPTS="-a :80 -T 127.0.0.1:6082 
             -f /etc/varnish/default.vcl 
             -S /etc/varnish/secret 
             -s malloc,1g 
             -p feature=+esi_disable_xml_check,+esi_ignore_other_elements 
             -p cli_buffer=16384 
             -p vcc_allow_inline_c=on"

我的默认.vcl:

if (bereq.url ~ "^.*(\/**esi**\/)+.*$") {
   set beresp.do_esi = true;
   set beresp.ttl = 0s;
} else { 
   set beresp.ttl = 3600s;
}

我的问题是当我使用通过访问说它触发的 vcl 代码时:http://localhost/lab/varnish

哪个渲染:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
</head>
<body>
    <esi:include src="http://localhost/lab/esi/body"/>
</body>
</html>

Varnish 没有读取 ESI 标签内的 url src,所以它只是渲染一个空的 body。

但是当我使用这段代码时:

if (bereq.url ~ "^.*(\/**lab**\/)+.*$") {
   set beresp.do_esi = true;
   set beresp.ttl = 0s;
} else { 
   set beresp.ttl = 3600s;
}

Varnish 成功渲染 ESI 标签内的内容,该标签由以下内容生成: http://localhost/lab/esi/body

如何让Varnish根据识别ESI“src”标签中的内容触发ESI片段渲染?

我已尝试设置 Surrogate-Capability 并使用 Surrogate-Control 进行检查,但对我来说它也不起作用。我没有线索了..

【问题讨论】:

    标签: varnish varnish-vcl esi varnish-4


    【解决方案1】:

    我不认为你可以。

    如果您将 beresp.do_esi 设置为 true,Varnish 将解析后端响应并将每个 esi:include 标记替换为其源内容。

    如果您不这样做,Varnish 将不会解析 beresp 并将其按原样提供给客户端。

    顺便问一下为什么要部分替换esi标签?

    【讨论】:

    • 我希望 varnish 使用已经缓存的内容提供给客户端,并且仅从 ESI 标签内的源中排除(请求到后端)内容.. 可以吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-29
    • 2011-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多