Varnish 不会清除 Plone 发送的请求

Varnish 不会清除 Plone 发送的请求

我已启动并运行 varnish 3.0.5,连接到 Plone 4 后端。我的请求已缓存,但无法可靠地清除,实际上只有在 ttl 到期后才会清除。plone.app.caching 是一个插件,每次修改对象时都会发送清除请求。这是 varnishlog:

   14 BackendOpen  b backend_0 127.0.0.1 54428 127.0.0.1 9088
   14 BackendXID   b 1585950387
   14 TxRequest    b PURGE
   14 TxURL        b /VirtualHostBase/https/example.com/path/VirtualHostRoot/pic/a.jpg
   14 TxProtocol   b HTTP/1.1
   14 TxHeader     b Host: localhost:9081
   14 TxHeader     b X-Varnish: 1585950387
   14 BackendClose b backend_0
   13 ReqStart     c 127.0.0.1 56614 1585950387
   13 RxRequest    c PURGE
   13 RxURL        c /VirtualHostBase/https/example.com/path/VirtualHostRoot/pic/a.jpg
   13 RxProtocol   c HTTP/1.1
   13 RxHeader     c Host: localhost:9081
   13 VCL_call     c recv pipe
   13 VCL_call     c hash
   13 Hash         c /VirtualHostBase/https/example.com/path/VirtualHostRoot/pic/a.jpg
   13 VCL_return   c hash
   13 VCL_call     c pipe pipe
   13 Backend      c 14 backend_0 backend_0
   13 ReqEnd       c 1585950387 1412603444.714001656 1412603505.824758053 0.000071526 0.000180483 61.110575914

在 default.vcl 中我配置了 acl 清除器、基本 vcl_hit 和 vcl_miss 函数,并且在 vcl_recv 内部我有:

if (req.request == "PURGE") {
    if (!client.ip ~ purge) {
        error 405 "This IP is not allowed to send purge requests.";
    }
    return (lookup);
}

清除后打开图像时,我仍然会得到旧版本,直到最大使用期限已过期。这是缩短的日志输出:

3 RxURL        c /VirtualHostBase/https/example.com:443/path/VirtualHostRoot/pic/a.jpg
3 RxProtocol   c HTTP/1.0
3 RxHeader     c Host: enertour.bz.it
3 VCL_call     c recv lookup
3 VCL_call     c hash
3 Hash         c /VirtualHostBase/https/example.com/path/VirtualHostRoot/pic/a.jpg
3 VCL_return   c hash
3 Hit          c 1585950403
3 VCL_call     c hit deliver
3 VCL_call     c deliver deliver
3 TxHeader     c Cache-Control: max-age=0, s-maxage=240, must-revalidate
3 TxHeader     c X-Cache-Rule: plone.content.file
3 TxHeader     c Age: 181

到目前为止,我所做的就是重写请求的哈希值,以匹配清除请求的哈希值。它们是相同的,但我的对象没有被清除,我不知道为什么?是因为请求主机发生了变化吗?

很高兴收到任何提示!

答案1

今天再次查看我的 vcl 时,我发现在修改过程中,清除函数滑到了我检查请求类型的行下。因此不允许清除,并且它在管道中完成。正确的顺序是:

if (req.request == PURGE) {
  ...
  return (lookup);
}
if (req.request != "(GET|HEAD)" {
  ...
  return (pass);
}

相关内容