假设没有更改 URL 或内部缓存键,对于完全刷新,最简单的方法是重新启动 Varnish,因为它在内存中维护其缓存。
如果不能接受快速重启,Rastislav 建议的 BAN 是一个很好的方法。只要你最长的 TTL,它就需要保持活跃,所以如果你经常需要完全刷新,BAN 列表将几乎是永久性的,因为禁止潜伏者(扫描不再相关的 BAN)可能总是认为你的 BAN有用
因此,在您的情况下,您的 VCL 将是:
# Highly recommend that you set up an ACL for IPs that are allowed
# to make the BAN call
acl acl_ban {
"localhost";
"1.2.3.4"/32;
}
sub vcl_recv {
if (client.ip ~ acl_ban && req.method == "BAN") {
ban("req.http.host == " + req.http.host);
# Throw a synthetic page so the request won't go to the backend.
return(synth(200, "Ban added"));
}
}
然而,正如 Carlos 在评论中指出的那样,这实际上会创建一个惰性失效(因此仅在请求时删除)。如果你想让这些对象经常被后台禁令潜伏者清除,你可以这样做:
# Highly recommend that you set up an ACL for IPs that are allowed
# to make the BAN call
acl acl_ban {
"localhost";
"1.2.3.4"/32;
}
sub vcl_recv {
if (client.ip ~ acl_ban && req.method == "BAN") {
# see below for why this is obj. rather than req.
ban("obj.http.host == " + req.http.host);
# Throw a synthetic page so the request won't go to the backend.
return(synth(200, "Ban added"));
}
}
sub vcl_backend_response {
# add any portions of the request that would want to be able
# to BAN on. Doing it in vcl_backend_response means that it
# will make it into the storage object
set beresp.http.host = bereq.http.host;
}
sub vcl_deliver {
# Unless you want the header to actually show in the response,
# clear them here. So they will be part of the stored object
# but otherwise invisible
unset beresp.http.host;
}
然后进行冲洗:
curl -X BAN http://example.com;