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,如需转载请自行联系原作者




相关文章
Squid 安装与配置
本文转载自:https://help.aliyun.com/knowledge_detail/41342.html Squid 介绍 Squid 是一个缓存 Internet 数据的软件,其接收用户的下载申请,并自动处理所下载的数据。
1490 0
|
15天前
|
Linux
linux环境下安装varnish
linux环境下安装varnish
|
网络协议 应用服务中间件 Shell
puppet连载12:linux安装nginx、openresty
服务端在/puppet/soft 里建nginx1102setup.sh,内容: !/bin/bash yum -y install wget libtool expat-devel gcc gcc-c++ glibc automake autocon...
893 0
|
tengine 应用服务中间件 Linux
linux下tengine2.2.0编译安装、开机启动、反向代理配置及健康检查
tengine2.2.0编译安装、开机启动、反向代理配置及健康检查 tengine是由淘宝发起的一个基于nginx的开源项目,nginx的吞吐量比较高、快速、稳定,而且反向代理和负载均衡使用nginx,也是最常见的。
1948 0
|
缓存 前端开发 区块链
|
缓存 应用服务中间件 Linux
|
缓存 前端开发 JavaScript