Fork me on GitHub

linux服务之varnish

https://www.varnish-cache.org/installation/redhat
varnish是现在很流行的一个HTTP(80)缓存加速解决方案,
varnish是基于内存的缓存加速.
Varnish 4.0:
    rpm --nosignature -i https://repo.varnish-cache.org/redhat/varnish-4.0.el6.rpm
    yum install varnish

Installing Varnish Cache is as simple as enabling our package repository and installing the packages. Varnish Cache 4.0 is supported on EL6, and Varnish Cache 3.0 is supported on EL5 and EL6.

sub vcl_recv {
if (req.request == "PURGE")
{if (!client.ip ~ purge)
{error 405 "Not allowed.";}
return(lookup);
}
if (req.http.host ~ "^google.com") {                  #web1对应的域名
set req.backend = web1;}
elseif (req.http.host ~ "^(www)|(my).baidu.com") {        #web2对应的域名
set req.backend = web2;}
else {
error 404 "Caesar's cache-server ! QQ: 189717888"; #如果域名不在以上范围的出错提示
#set req.backend = web1;
}
if (req.request != "GET" && req.request != "HEAD") {
return(pipe);
}
elseif (req.url ~ "\.(php|cgi)($|\?)")                #动态页面直接通过,不缓存
{
return(pass);
}
return(lookup);
}
sub vcl_hit {
if (req.request == "PURGE") {
set obj.ttl = 0s;
error 200 "Purged.";
}
}
sub vcl_miss {
if (req.request == "PURGE") {
error 404 "Not in cache.";
}
}

posted on 2014-06-30 09:40  阳光-源泉  阅读(270)  评论(0编辑  收藏  举报

导航