varnish 返回503 错误

hanchunliu 发布于 2013/01/29 18:13
阅读 2K+
收藏 0
# 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 webserver1 {
  .host = "10.100.100.202";
  .port = "80";
  .connect_timeout = 8s;
  .first_byte_timeout = 8s;
  .between_bytes_timeout = 5s;
  .probe = {
  .url = "/index.action";
  .interval = 60s;
  .timeout = 3s;
  .window = 8;
  .initial = 3;
  .threshold = 3;
   }    
}
#瀹氫箟acl锛岀敤浜庣鐞嗙紦瀛?
acl purge {
   "localhost";
   "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 {
     if (req.restarts == 0) {
 	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 == "purge") {
        if (!client.ip ~ purge) {
        error 405 "Not allowed.";
        }
     }
#缂撳瓨鏂规硶鏄疓ET鍙奌EAD鐨勮姹?
if (req.request != "GET" && req.request != "HEAD") {
#         /* We only deal with GET and HEAD by default */
         return (pass);
     }
#涓嶇紦瀛樿璇佸強cookie淇℃伅
     if (req.http.Authorization || req.http.Cookie) {
#         /* Not cacheable by default */
         return (pass);
     }
#璇锋眰鏄疓ET涓斾互jsp鍜宒o缁撳熬鎴栧寘鍚?鐨剈rl鐩存帴璁块棶鍚庣鏈嶅姟鍣ㄤ笉缂撳瓨
     if (req.request =="GET"&&req.url ~"(?i)\.(jsp|do)($|\?)") {
     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 = 120 s;
 		return (hit_for_pass);
     }
#浠ss銆乯s銆乭tml銆乭tm缁撳熬鐨勬枃浠剁紦瀛?鍒?
if (req.request == "GET" && req.url ~ "\.(css|js|html|htm)$") {
     set beresp.ttl = 300s;     
     }
#鍥剧墖缂撳瓨1灏忔椂
     if (req.request == "GET" && req.url ~ "\.(gif|jpg|jpeg|bmp|png|tiff|tif|ico|img|bmp|wmf)$") {
     set beresp.ttl = 3600s;
     }
#瑙嗛缂撳瓨10澶?
if (req.request == "GET" && req.url ~ "\.(svg|swf|mp3|mp4|m4a|wav|rmvb|avi|wmv)$") {
     set beresp.ttl = 10d;
     }
 return (deliver);
 }
# 
 sub vcl_deliver {
     if (obj.hits > 0) {
	set resp.http.X-Cache = "Hit from t.people.com.cn";
     }  else {
        set resp.http.X-Cache = "Miss from t.people.com.cn";     
     }
     return (deliver);
 }
# 
# sub vcl_error {
#     set obj.http.Content-Type = "text/html; charset=utf-8";
#     set obj.http.Retry-After = "5";
#     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);
 }
varnish3.0.3配置文件如上,在我没有优化前不出现503,我优化了一些配置服务器刚启动还能访问,过1分钟再访问就是503了,那位大侠有有精力帮忙看看,感谢!!
加载中
0
h
hanchunliu

我来结贴吧:

10   .connect_timeout = 8s;
11   .first_byte_timeout = 8s;
12   .between_bytes_timeout = 5s;
13   .probe = {
14   .url ="/index.action";
15   .interval = 60s;
16   .timeout = 3s;
17   .window = 8;
18   .initial = 3;
19   .threshold = 3;
20    }
把这段关于时间超时的配置去掉,就不再报了

返回顶部
顶部