【发布时间】:2021-03-08 20:20:13
【问题描述】:
我假设我在 Varnish 配置中一定犯了一个错误。 (我正在运行版本 6.0.7。)这是相关部分:
####----SECTION THREE: PURGE RULES----####
# Access Control List to define which IPs can purge content
acl purge {
"localhost";
"127.0.0.1";
"<my home IP address>";
"::1";
}
####----SECTION FOUR: PROCESSING RULES----####
sub vcl_recv {
# Do not allow purging from non-approved IPs
if (req.method == "PURGE") {
if (!client.ip ~ purge) {
return (synth(405, "This IP is not allowed to send PURGE requests."));
}
return (purge);
}
# Allow banning regexes
if (req.method == "BAN") {
if (!client.ip ~ purge) {
return (synth(405, "This IP is not allowed to send BAN requests."));
}
ban("req.http.host == " + req.http.host + " && req.url ~ ^" + req.url);
return (synth(200, "Ban added"));
}
# Allow purging regexes
if (req.method == "PURGE") {
if (req.http.X-Purge-Method == "regex") {
ban("req.url ~ " + req.url + " && req.http.host ~ " + req.http.host);
return (synth(200, "Banned"));
} else {
return (purge);
}
(注意:在我的设置中,Varnish 在端口 6081 上运行,前面有 HAProxy。)
使用此设置,无论是从我的家庭 IP 地址还是正在运行 Varnish 的服务器,我都可以通过运行从 Varnish 缓存中清除各个页面,例如:
curl -i -X PURGE https://example.com/page/
我还可以通过运行从 Varnish 缓存中清除整个域,例如:
curl -i -X BAN https://example.com
同样,我可以通过运行从 Varnish 缓存中清除单个页面,例如:
curl -i -X PURGE http://<IP of Varnish server>:6081/page/ -H "Host: example.com”
我还可以通过运行从 Varnish 缓存中清除整个域,例如:
curl -i -X BAN http://<IP of Varnish server>:6081 -H "Host: example.com”
但我注意到我无法通过运行以下任一方式清除整个域:
curl -i -X PURGE https://example.com
或:
curl -i -X PURGE http://<IP of Varnish server>:6081 -H "Host: example.com”
要清除整个域,我必须改用 BAN。我不知道这是问题还是配置错误,但似乎是,因为虽然我已经读过 PURGE 不用于清除所有内容,但我正在使用的 Wordpress 插件似乎正在尝试通过发送 PURGE 请求当我点击“清除所有清漆缓存”按钮时,domain.com/.*。
坦率地说,这让我很困惑。因为它在插件本身或我从命令行尝试时都不起作用。我错过了什么?插件是不是已经过时了? Varnish 曾经能够以这种方式清除整个缓存吗?我会很感激任何指示。谢谢!
【问题讨论】:
标签: varnish varnish-vcl varnish-4