|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
如果您觉得本篇CentOSLinux教程讲得好,请记得点击右边漂浮的分享程序,把好文章分享给你的小伙伴们!下载地址:http://pkgs.fedoraproject.org/repo/pkgs/varnish/varnish-2.1.3.tar.gz/357d99a760de173d841ac37bf2052be8/varnish-2.1.3.tar.gz
1、装置varnish
#tarzxvfvarnish-2.1.3.tar.gz
#cdvarnish-2.1.3
#/configureCprefix=/opt/varnish
#make&&makeinstall
2、设置装备摆设实例
#vi/opt/varnish/etc/varnish/test.vcl
backendbbs{
.host="202.105.182.55";
.port="80";}
acllocal{"localhost";
"192.168.2.4";
}
subvcl_recv{
if(req.request=="PURGE"){
if(!client.ip~local){
error405"NotAllowed.";
return(lookup);
}
}
if(req.request=="GET"&&req.url~".(jpg|png|gif|swf|jpeg|ico)$"){
unsetreq.http.cookie;
}
if(req.http.x-forwarded-for){
setreq.http.X-Forwarded-For=
req.http.X-Forwarded-For","client.ip;
}else{
setreq.http.X-Forwarded-For=client.ip;
}
if(req.request!="GET"&&
req.request!="HEAD"&&
req.request!="PUT"&&
req.request!="POST"&&
req.request!="TRACE"&&
req.request!="OPTIONS"&&
req.request!="DELETE"){
return(pipe);
}
if(req.request!="GET"&&req.request!="HEAD"){
return(pass);
}
if(req.http.Authorization||req.http.Cookie){
return(pass);
}
if(req.request=="GET"&&req.url~".(php)($|?)"){
return(pass);
}
return(lookup);
}
subvcl_pipe{return(pipe);
}
subvcl_pass{return(pass);
}
subvcl_hash{
setreq.hash+=req.url;
if(req.http.host){
setreq.hash+=req.http.host;
}else{
setreq.hash+=server.ip;
}
return(hash);
}
subvcl_hit{
if(!obj.cacheable){
return(pass);
}
return(deliver);
}
subvcl_miss{
return(fetch);
}
subvcl_fetch{
if(!beresp.cacheable){
return(pass);
}
if(beresp.http.Set-Cookie){
return(pass);
}
if(beresp.http.Set-Cookie){
return(pass);
}
if(beresp.http.Pragma~"no-cache"||
beresp.http.Cache-Control~"no-cache"||
beresp.http.Cache-Control~"private"){
return(pass);
}
if(req.request=="GET"&&req.url~".(js|CSS|mp3|jpg|png|gif|swf|jpeg|ico)$")
{
setberesp.ttl=7d;
}
return(deliver);
}
subvcl_deliver{setresp.http.x-hits=obj.hits;
if(obj.hits>0){
setresp.http.X-Cache="HITcqtel-bbs";
}else{
setresp.http.X-Cache="MISScqtel-bbs";
}
}
subvcl_error{
setobj.http.Content-Type="text/html;charset=utf-8";
synthetic{"
<?xmlversion="1.0"encoding="utf-8"?>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>"}obj.status""obj.response{"</title>
</head>
<body>
<h1>Error"}obj.status""obj.response{"</h1>
<p>"}obj.response{"</p>
<h3>GuruMeditation:</h3>
<p>XID:"}req.xid{"</p>
<hr>
<address>
<ahref="http://www.zhnews.net/">bbscacheserver</a>
</address>
</body>
</html>
"};
return(deliver);
}
启动varnish:
#ulimit-SHn51200
#useradd-s/sbin/nologinwww
##/opt/varnish/sbin/varnishd-uwww-gwww-f/opt/varnish/etc/varnish/test.vcl-a192.168.2.4:80-sfile,/data/varnish_cache/varnish_cache.data,1G-w1024,5100,10-t3600-T192.168.2.4:3500
参数:-u以甚么用运转
-g以甚么组运转
-fvarnish设置装备摆设文件
-a绑定IP和端口
-svarnish缓存文件地位与巨细
-w最小,最年夜线程和超不时间
-Tvarnish治理端口,重要用来消除缓存
-sfile,/data/varnish_cache/varnish_cache.data,1G缓存目次,这个32位体系不克不及跨越2G的,建议应用64位体系,还有想要更快的速度,把这个目次改成内存缓存会更快,内存越年夜越好
停滞varnish:
#pkillvarnishd
欢迎大家来到仓酷云论坛! |
|