问题描述
我正在 Digital Ocean Ubuntu VM 上运行一个独立的 varnish 实例,它基本上运行良好.该设置用于加载位于其他任何地方的旧 wordpress 服务器.这很有效,但我很难清除内容.在谈论清除时,我的意思是使 URL 的缓存无效以强制清漆从后端获取新版本(只是为了确保我看到了对清除/禁止的一些刺激).
I'm running a stand alone instance of varnish on a Digital Ocean Ubuntu VM which basically works fine. The setup is used to take load of an older wordpress server that sits anyhwere else. That works quite well but i'm having a hard time getting content purged. And when talking about purge i mean to invalidate the cache for a URL to force varnish to fetch a fresh version from the backend (just to make sure as i've seen some irritation about purge/ban).
我已经设置了一个用于清除的 ACL,就我在 varnishlog 中看到的而言,清除被接受 - 一方面来自 WordPress 博客(W3TC 处理清除的地方)以及来自我尝试清除的本地控制台的 es使用 curl -X PURGE http://url.to.purge
I have setup an ACL for purge and as far as i can see with varnishlog the purges get accepted - on one side from the WordPress blog (where W3TC handles the purges) as well es from the local console where i tried to purge with curl -X PURGE http://url.to.purge
问题是,无论我在本地做什么,我仍然在浏览器中获得旧版本的 URL.
The problem is that i still get the old versions of the URL in the browser on matter what i do locally.
这就是我在 vcl_recv 中处理清除的方式:
This is how i handle purge in vcl_recv:
if (req.method == "PURGE") {
if (!client.ip ~ purge) {
return(synth(405,"Not allowed."));
}
return (purge);
}
每次清除时我都会收到 VCL_error(200, Purged) 所以我想这可能没问题.
and i get VCL_error(200, Purged) on every purge so i guess it's probably ok.
看来我还是做错了.在重新启动 service varnish 后,整个缓存会刷新,页面也会刷新 - 在此之前清漆会保留所有内容 - 无论我清除了多少.
Looks like i'm still doing things wrong. After giving service varnish a restart the full cache refreshes and the pages refresh too - until then varnish keeps everything for ages - no matter how much i'm purging.
我的 Varnish 版本是 4.0.3.
my Varnish version is 4.0.3.
有什么想法吗?
谢谢,
弗兰克
推荐答案
在 Varnish 6 和 vcl 4.1 上有相同的行为.解决它的唯一方法是像这样明确定义 sub vcl_purge:
Got same behavior on Varnish 6 with vcl 4.1. The only way to solve it was explicitly define sub vcl_purge like this:
sub vcl_purge {
set req.method = "GET";
set req.http.X-Purger = "Purged";
return (restart);
}
没有找到原因,这可能不是您想要的,因为清除后它将从后端获取内容,而无需等待客户端请求.但仍然没有找到另一种方式,这对我来说已经足够了.
Didn't find the reason and this may not be exactly what you want because after purge it will get content from the backend without waiting for client request. But still didn't find another way and this is good enough for me.
这篇关于清漆:Purge 说它有效,但不会删除旧内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!