7.1 Varnish VCL








根据以上的配置增加集群,修改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的更多相关文章
- 7.3 Varnish VCL 常用函数
- 7.5 Varnish VCL的变量和应用片段
- 7.4 Varnish VCL的子程序
- varnish
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,bi ...
- Varnish 4.0 实战(转)
简介 Varnish 是一款高性能且开源的反向代理服务器和 HTTP 加速器,其采用全新的软件体系机构,和现在的硬件体系紧密配合,与传统的 squid 相比,varnish 具有性能更高.速度更快.管 ...
- 使用Varnish代替Squid做网站缓存加速器的详细解决方案----转载
[文章作者:张宴 本文版本:v1.2 最后修改:2008.01.02 转载请注明出处:http://blog.s135.com] 我曾经写过一篇文章──<初步试用Squid的替代产品──Varn ...
- Varnish缓存服务器的搭建配置手册
Varnish缓存服务器的搭建配置手册 1.Varnish官方环境依赖提示 Installing Varnish Cache is as simple as enabling our package ...
- Varnish缓存服务
Varnish缓存服务详解及应用实现 1.varnish的基本介绍 Varnish 的作者Poul-Henning Kamp是FreeBSD的内核开发者之一,他认为现在的计算机比起1975年已 ...
- Varnish缓存服务详解及应用实现
1.varnish的基本介绍 Varnish 的作者Poul-Henning Kamp是FreeBSD的内核开发者之一,他认为现在的计算机比起1975年已经复杂许多.在1975年时,储存媒介只有 ...
随机推荐
- 端口打开和关闭do while
;Author : Bing Song ;// ;Usage: modify “logfile" according to actual drictory getdir logdir #获取 ...
- JavaWeb之过滤器
过滤器 什么是过滤器 1示意图: 过滤器的作用: 1.过滤器的作用好比一个保安.是servlet规范中的技术 2.用户在访问应用的资源之前或者之后,可以对请求做出一定的处理 编写过滤器步骤: 1.编写 ...
- 牛顿迭代法--求任意数的开n次方
牛顿迭代法是求开n次方近似解的一种方法,本文参考. 引言 假如\(x^n = m\),我们需要求x的近似值. 我们设\(f(x) = x^n - m\), 那么也就是求该函数f(x)=0时与x轴的交点 ...
- python学习记录(持续更新)--最最最基础的一部分(方法,异常处理,注释,类)
写在前面 本系列教程针对有一定编程经验的伙伴快速入门python基础,一些涉及开发的常识问题,本文并不涉及. 方法 function def greet_user(name): print(f'Hi ...
- python3升级pip报错ImportError: cannot import name 'main'
把系统的python版本从默认的2切换到3后,使用pip3安装依赖报错,如下: Traceback (most recent call last): File , in <module> ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 排版:设定大写文本
<!DOCTYPE html> <html> <head> <title>菜鸟教程(runoob.com)</title> <meta ...
- 学习笔记(10)- 智能会话框架rasa
https://rasa.com/ 阿里用过这个,贝壳也在用这个. 优点: 有中文版本(https://github.com/crownpku/rasa_nlu_chi): 2018年发布,文档多,业 ...
- web组件化开发第一天
技术选型 html5 css3 jq 应用的插件 FullPage.js 一.建一个测试页面,测试静态的功能 <!DOCTYPE html> <html> <head&g ...
- 靠谱的Pycharm安装详细教程
如何在本机上下载和安装Pycharm,具体的教程如下: 1.首先去Pycharm官网,或者直接输入网址:http://www.jetbrains.com/pycharm/download/#secti ...
- Go语言中的数组与数组切片
Go中的数组与C的数组一样,只是定义方法不同 c: int a[10][10] Go [10][10]int 定义并初始化 array1 := [5]int{1,2,3,4,5} 变量名 := [in ...