配置varnish 批量刷新缓存,
参考 :https://www.varnish-cache.org/docs/3.0/tutorial/purging.html?highlight=ban
在sub vcl_recv 中添加
if (req.request == "BAN") {
if (!client.ip ~purge){
error 405 "Not allowed";
}
ban("req.http.host == " +req.http.host+" && req.url ~ "+req.url);
error 200 "Ban added";
}
php,刷新函数
function ban($ip,$host, $uri)
{
$errstr = '';
$errno = '';
$fp = fsockopen ($ip, 80, $errno, $errstr, 2);
if (!$fp)
{
return false;
}
else
{
$out = "BAN $url HTTP/1.1\r\n";
$out .= "Host:$host\r\n";
$out .= "Connection: close\r\n\r\n";
fputs ($fp, $out);
while (!feof($fp))
{
$out = fgets($fp,4096);
}
fclose ($fp);
return true;
}
}
uri可以是目录 ("/"结尾),也可以匹配正则,(如 .*\.png)