根据以上的配置增加集群,修改default.vcl

# This is a basic VCL configuration file for varnish.  See the vcl()
# man page for details on VCL syntax and semantics.
#
# Default backend definition. Set this to point to your content
# server.
#
backend b1 {
.host = "127.0.0.1";
.port = "";
.connect_timeout = 1s;
.first_byte_timeout = 5s;
.between_bytes_timeout = 2s;
} backend b2{
.host = "127.0.0.1";
.port = "";
.connect_timeout = 1s;
.first_byte_timeout = 5s;
.between_bytes_timeout = 2s;
}
director d1 random{
.retries = ;
{
.backend = b1;
.weight = ;
}
{
.backend = b2;
.weight = ;
}
} # ac1 purgeallow {
# "127.0.0.1";
# }
#
# 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 {
set req.backend=d1;
if(req.request == "PURGE"){
# if(!client.ip ~ purgeallow){
# error "not allowed.";
# }
return(lookup);
}
if(req.request == "GET" && req.url ~ "\.(jpg|png|gif|swf|flv|ico|jpeg)$"){
# set req.backend=b1;
unset req.http.cookie;
}
if(req.request == "GET" && req.url ~ "(?!)\.jsp($|\?)"){
# set req.backend=b2;
return(pass);
}
if (req.restarts == ) {
if (req.http.x-forwarded-for) {
set req.http.X-Forwarded-For =
req.http.X-Forwarded-For + ", " + client.ip;
} else {
set req.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") {
/* Non-RFC2616 or CONNECT which is weird. */
return (pipe);
}
if (req.request != "GET" && req.request != "HEAD") {
/* We only deal with GET and HEAD by default */
return (pass);
}
if (req.http.Authorization || req.http.Cookie) {
/* Not cacheable by default */
return (pass);
}
return (lookup);
} sub vcl_pipe {
# # Note that only the first request to the backend will have
# # X-Forwarded-For set. If you use X-Forwarded-For and want to
# # have it set for all requests, make sure to have:
# # set bereq.http.connection = "close";
# # here. It is not set by default as it might break some broken web
# # applications, like IIS with NTLM authentication.
return (pipe);
}
#
sub vcl_pass {
return (pass);
}
#
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_hit {
return (deliver);
}
#
sub vcl_miss {
return (fetch);
}
#
sub vcl_fetch {
if (beresp.ttl <= 0s ||
beresp.http.Set-Cookie ||
beresp.http.Vary == "*") {
# /*
# * Mark as "Hit-For-Pass" for the next 2 minutes
# */
set beresp.ttl = s;
return (hit_for_pass);
}
return (deliver);
}
#
sub vcl_deliver {
return (deliver);
}
#
# sub vcl_error {
# set obj.http.Content-Type = "text/html; charset=utf-8";
# set obj.http.Retry-After = "";
# synthetic {"
# <?xml version="1.0" encoding="utf-8"?>
# <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//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>Guru Meditation:</h3>
# <p>XID: "} + req.xid + {"</p>
# <hr>
# <p>Varnish cache server</p>
# </body>
# </html>
# "};
# return (deliver);
# }
#
sub vcl_init {
return (ok);
}
#
sub vcl_fini {
return (ok);
}

运行测试(启动tomcat1,tomcat2)

7.1 Varnish VCL的更多相关文章

  1. 7.3 Varnish VCL 常用函数

  2. 7.5 Varnish VCL的变量和应用片段

  3. 7.4 Varnish VCL的子程序

  4. varnish

    html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,bi ...

  5. Varnish 4.0 实战(转)

    简介 Varnish 是一款高性能且开源的反向代理服务器和 HTTP 加速器,其采用全新的软件体系机构,和现在的硬件体系紧密配合,与传统的 squid 相比,varnish 具有性能更高.速度更快.管 ...

  6. 使用Varnish代替Squid做网站缓存加速器的详细解决方案----转载

    [文章作者:张宴 本文版本:v1.2 最后修改:2008.01.02 转载请注明出处:http://blog.s135.com] 我曾经写过一篇文章──<初步试用Squid的替代产品──Varn ...

  7. Varnish缓存服务器的搭建配置手册

    Varnish缓存服务器的搭建配置手册 1.Varnish官方环境依赖提示 Installing Varnish Cache is as simple as enabling our package ...

  8. Varnish缓存服务

    Varnish缓存服务详解及应用实现   1.varnish的基本介绍   Varnish 的作者Poul-Henning Kamp是FreeBSD的内核开发者之一,他认为现在的计算机比起1975年已 ...

  9. Varnish缓存服务详解及应用实现

    1.varnish的基本介绍    Varnish 的作者Poul-Henning Kamp是FreeBSD的内核开发者之一,他认为现在的计算机比起1975年已经复杂许多.在1975年时,储存媒介只有 ...

随机推荐

  1. shell coding about mac ox

    1, mac path---http://blog.csdn.net/playstudy/article/details/50149021 Mac系统的环境变量,加载顺序为:/etc/profile ...

  2. PAT T1005 Programming Pattern

    建立后缀数组,遍历height数组找到连续大于len的最长子序列~ #include<bits/stdc++.h> using namespace std; ; char s[maxn]; ...

  3. PTA的Python练习题(六)

    从 第3章-8 字符串逆序 开始 1. n = str(input()) n1=n[::-1] print(n1) 2. 不是很好做这道题,自己还是C语言的思维,网上几乎也找不到什么答案 s = in ...

  4. Maven打包项目失败;报错:Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on project Hello: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/we

    报错信息: E:\MIKEY\mikey\HTML5\TestMaven_01>mvn package [INFO] Scanning for projects... [INFO] [INFO] ...

  5. C. Swap Letters 01字符串最少交换几次相等

    C. Swap Letters time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  6. 关于Android Studio中点9图的编译错误问题

    Android中的点9图想必大家都非常熟悉了,能够指定背景图片的缩放区域和文本内容的显示区域,常见如QQ聊天界面的背景气泡这种文本内容不固定并需要适配的应用场景. 这里也给大家准备了一张图,详细介绍了 ...

  7. ImagePullBackOff 错误处理

    kubectl create -f nginx-deployment.yaml 执行之后,kubectl get pods 一致出现 ImagePullBackOff,一直无法执行成功. yaml文件 ...

  8. Golang 如何交叉编译

    Golang 支持交叉编译,即在一个平台上生成另一个平台的可执行程序.方法如下: Mac 下编译 Linux 和 Windows 64位可执行程序 CGO_ENABLED=0 GOOS=linux G ...

  9. 卸载sql server 2008

    一.    SQL2008卸载. 1.从控制面板卸载 1)点击计算机右下角“开始”,点击“控制面板” 2)点击“卸载程序”. 3)在程序列表中找到“Microsoft SQL Server 2008” ...

  10. python正则表达式错误集

    这篇博文主要记载一些个人的(python)正则表达式的常见错误以及误区,所以,不一定全面,不一定具有权威.但我会把每个例子列出来,争取用事实说话. 大括号中空格问题 In [15]: re.match ...