我正在寻找一种方法来清除 Varnish 中所有域和所有 URL 的缓存。
目前,我需要为每个 URL 发出单独的命令,例如:
curl -X PURGE http://example.com/url1
curl -X PURGE http://example.com/url1
curl -X PURGE http://subdomain.example.com/
curl -X PURGE http://subdomain.example.com/url1
// etc.
虽然我正在寻找一种方法来做类似的事情
curl -X PURGE http://example.com/*
这将清除 example.com 下的所有 URL,但也会清除 example.com 子域中的所有 URL,基本上所有由 Varnish 管理的 URL。
知道如何实现这一目标吗?
这是我当前的 VCL 文件:
vcl 4.0;
backend default {
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_recv {
# Command to clear the cache
# curl -X PURGE http://example.com
if (req.method == "PURGE") {
return (purge);
}
}
最佳答案
在 Varnish 4.0 中,我最终使用 ban
实现了它。命令:
sub vcl_recv {
# ...
# Command to clear complete cache for all URLs and all sub-domains
# curl -X XCGFULLBAN http://example.com
if (req.method == "XCGFULLBAN") {
ban("req.http.host ~ .*");
return (synth(200, "Full cache cleared"));
}
# ...
}
关于caching - 如何清除 Varnish 中的完整缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38892021/