sub vcl_fini {
return (ok);
}
四、启动
启动命令
/usr/local/varnish3.0/sbin/varnishd -f /usr/local/varnish3.0/etc/varnish/default.vcl -s malloc,2G -a 0.0.0.0:80 -w 1024,51200,10 -t
3600 -T 192.168.100.2:3500
检测配置文件是否存在错误
/usr/local/varnish3.0/sbin/varnishd -C -f /usr/local/varnish3.0/etc/varnish/default.vcl
参数
-a address:port 监听端口
-f 指定配置文件
-s 指定缓存类型 malloc为内存, file 文件缓存
-t 默认TTL
-T address:port 管理端口
-w 最小线程,最大线程,超时时间
记录varnish日志
/usr/local/varnish3.0/bin/varnishncsa -w /var/logs/varnish.log &
五、缓存刷新
php脚步如下
<?php
function purge($ip, $url)
{
$errstr = '';
$errno = '';
$fp = fsockopen ($ip, 80, $errno, $errstr, 2);
if (!$fp)
{
return false;
}
else
{
$out = "PURGE $url HTTP/1.1\r\n";
$out .= "Host:image.android.com\r\n";
$out .= "Connection: close\r\n\r\n";
fputs ($fp, $out);
$out = fgets($fp , 4096);
fclose ($fp);
return true;
}
}
if(isset($_POST['content'])) {
//$str=str_replace("\r","<br>",$_POST[content]);
$arr=(explode("\n",$_POST['content']));
$Server="192.168.100.2";
foreach ($arr as $value)
{
echo $value;
purge($Server, $value);
echo "刷新成功"."<br />";
}
//purge($Server, "$_POST[content]");
//echo "刷新成功";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>varnish缓存刷新</title>
</head>
<body>
<form action="?" method="post">
填写需要刷新url<br />
<textarea cols="40" rows="10"></textarea>
<input type="submit" value="submit" />
</form>
</body>
</html>
###########
通过管理端口清除缓存
telnet 192.168.100.2 3500
3.0版本 为ban.url aaaa.html
2.版本为purge.url aaaa.html