varnish安装配置

爱慕尔商城!

centos/redhat

1、安装


#rpm --nosignature -i http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release-3.0-1.noarch.rpm


#yum install varnish

2、配置

default.vcl


# This is a basic VCL configuration file for varnish. See the vcl(7)
# man page for details on VCL syntax and semantics.

# Default backend definition. Set this to point to your content
# server.

backend default {
.host = "192.168.75.122";
.port = "80";
.probe = {
 .url = "/";
 .interval = 5s;
 .timeout = 1 s;
 .window = 5;
 .threshold = 3;
}
}

backend test {
.host = "192.168.0.83";
.port = "80";
#.probe = {
# .url = "/";
# .interval = 5s;
# .timeout = 1 s;
# .window = 5;
# .threshold = 3;
# }
}
#director ecae_director round-robin {
#{
# .backend = default;
#}
#{
# .backend = test;
#}
#}
acl purge {
"localhost";
"192.168.210.0"/24;
"192.168.51.0"/24;
}

# Below is a commented-out copy of the default VCL logic. If you
# redefine any of these subroutines, the built-in logic will be
# appended to your code.
sub vcl_recv {
if (req.request == "PURGE") {
 if (!client.ip ~ purge) {
 error 405 "Not allowed.";
 }
 return(lookup);
}
if (req.http.host ~ "(?i)^(images.)?test.cn$") {
 set req.http.host = "images.test.cn";
 set req.backend = test;
} elsif (req.http.host ~ "(?i)^images2.test.cn$") {
 set req.http.host = "images2.test.cn";
 set req.backend = test;
} else {
 error 404 "Unknown virtual host";
}
if (req.url ~ "\.(gif|jpg|jpeg|swf|css|js|flv|mp3|mp4|pdf|ico|png)(\?.*|)$") {
 unset req.http.cookie;
 set req.url = regsub(req.url, "\?.*$", "");
}
if (req.http.cookie) {
 unset req.http.cookie;
}
if (req.http.Accept-Encoding) {
 if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$") {
 # No point in compressing these
 remove req.http.Accept-Encoding;
 } elsif (req.http.Accept-Encoding ~ "gzip") {
 set req.http.Accept-Encoding = "gzip";
 } elsif (req.http.Accept-Encoding ~ "deflate") {
 set req.http.Accept-Encoding = "deflate";
 } else {
 # unknown algorithm
 remove req.http.Accept-Encoding;
 }
}
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.";
}
}

sub vcl_hash {
hash_data(req.url);
if (req.http.host) {
 hash_data(req.http.host);
} else {
 hash_data(server.ip);
}
return (hash);
}

sub vcl_fetch {
if (req.request == "GET") {
unset beresp.http.set-cookie;
}
if (req.url ~ "\.(gif|jpg|jpeg|swf|css|js|flv|mp3|mp4|pdf|ico|png)(\?.*|)$") {
unset beresp.http.set-cookie;
set beresp.ttl = 365d;
}
}

sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
}

3、启动


varnishd -f /etc/varnish/default.vcl -s malloc,3G -w 8,500,300 -T 127.0.0.1:2000 -a 0.0.0.0:80

爱慕尔商城欢迎您的光临!
穿衣打扮 
城市物语



    本文转自yuangang_love 51CTO博客,原文链接:http://blog.51cto.com/linux008/1195549,如需转载请自行联系原作者




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值