免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3751 | 回复: 0
打印 上一主题 下一主题

Varnish配置,Error 503解决之道 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-02-03 10:04 |只看该作者 |倒序浏览
首先,说说Varnish的配置方法。
Varnish的启动需要配置文件(*.vcl),以及其他一些启动参数配合(具体参数在此略去不谈,man一下会看到一切)。我安装的是Varnish-2.0.4
整个安装过程如下:
#./configure –prefix=/usr/local/varnish –enable-developer-waring –enable-debugging-sybmbles –enable-werror
#make
#make install
编译安装完成,然后就需要启动它,我写的启动文件如下:
###Start.sh######
#!/bin/sh
#file:start.sh
date -u
/usr/local/varnish/sbin/varnishd -a 173.26.100.206:80 -s file,/cache/varnish/V,1024m -f /usr/local/varnish/etc/varnish/default.vcl -p thread_pool_max=1500 -p thread_pools=5 -p listen_depth=512 -p client_http11=on -p connect_timeout = 1s -p send_timeout = 20s
以下是deault.vcl配置
######defualt.vcl########
backend default {
.host = “173.26.100.206″;
.port = “81″;
}
#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 != “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 req.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 {
set req.hash += req.url;
if (req.http.host) {
set req.hash += req.http.host;
} else {
set req.hash += server.ip;
}
return (hash);
}
sub vcl_hit {
if (!obj.cacheable) {
return (pass);
}
return (deliver);
}
sub vcl_miss {
return (fetch);
}
sub vcl_fetch {
if (!obj.cacheable) {
return (pass);
}
if (obj.http.Set-Cookie) {
return (pass);
}
set obj.prefetch = -30s;
return (deliver);
}
sub vcl_deliver {
return (deliver);
}
sub vcl_discard {
/* XXX: Do not redefine vcl_discard{}, it is not yet supported */
return (discard);
}
sub vcl_prefetch {
/* XXX: Do not redefine vcl_prefetch{}, it is not yet supported */
return (fetch);
}
sub vcl_timeout {
/* XXX: Do not redefine vcl_timeout{}, it is not yet supported */
return (discard);
}
sub vcl_error {
set obj.http.Content-Type = “text/html; charset=utf-8″;
synthetic {”
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
Error “} obj.status ” ” obj.response {”
“} obj.response {”
Guru Meditation:
XID: “} req.xid {”
Varnish
“};
return (deliver);
}
如此配置,运行./Start.sh启动Varnish监听本机80端口,backend为Apache监听的81端口。问题出现了,通过81端口访问,正常响应,浏览器获得正确页面;访问81端口,出现503 error。
对于这个问题在网上搜了很多方法试图解决,比较多的办法是在配置文件里修改添加
backend default {
.host = “173.26.100.206″;
.port = “81″;
###下面三行为新加配置
.connect_timeout = 1s;
.first_byte_timeout = 5s;
.between_bytes_timeout = 2s;
}
事实上并不奏效,自己摸索良久,偶然将start.sh中一些启动选项去掉,结果发现可以正常响应了。
新的启动文件如下:
####Start.sh#####
#!/bin/sh
#file:start.sh
date -u
/usr/local/varnish/sbin/varnishd -a 173.26.100.206:80 -s file,/cache/varnish/V,1024m -f /usr/local/varnish/etc/varnish/default.vcl -p thread_pool_max=1500 -p thread_pools=5 -p listen_depth=512 -p client_http11=on
去掉了connect_timeout和send_timeout,相当于使用系统默认配置。
结果一切归于正常,Varnish又一次表现出高速的http代理能力。


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/107680/showart_2169620.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP