Caching 清漆连接错误

Caching 清漆连接错误,caching,varnish,varnish-vcl,Caching,Varnish,Varnish Vcl,我有这个vcl varnish配置文件,但当我想从应用服务器上清除时,它抛出了一个错误。有什么问题吗 我有5个应用服务器,除了管理员和论坛之外的所有内容都在缓存中,但是,当我从应用服务器中清除用户时,它会抛出以下错误:无法连接到192.168.11.41:6082上的varnishadm;“拒绝连接” 后端app01{ .host=“app01.xxx.com”; .port=“80”; .连接超时=0.7s; .第一字节超时=30s; .字节之间\u超时=30s; .probe={ .url=

我有这个vcl varnish配置文件,但当我想从应用服务器上清除时,它抛出了一个错误。有什么问题吗

我有5个应用服务器,除了管理员和论坛之外的所有内容都在缓存中,但是,当我从应用服务器中清除用户时,它会抛出以下错误:无法连接到192.168.11.41:6082上的varnishadm;“拒绝连接”

后端app01{
.host=“app01.xxx.com”;
.port=“80”;
.连接超时=0.7s;
.第一字节超时=30s;
.字节之间\u超时=30s;
.probe={
.url=“/”;
.间隔=5s;
.超时=1s;
.window=5;
.阈值=3;
}
}
后端app02{
.host=“app02.xxx.com”;
.port=“80”;
.连接超时=0.7s;
.第一字节超时=30s;
.字节之间\u超时=30s;
.probe={
.url=“/”;
.间隔=5s;
.超时=1s;
.window=5;
.阈值=3;
}
}
后端应用程序03{
.host=“app03.xxx.com”;
.port=“80”;
.连接超时=0.7s;
.第一字节超时=30s;
.字节之间\u超时=30s;
.probe={
.url=“/”;
.间隔=5s;
.超时=1s;
.window=5;
.阈值=3;
}
}
后端app04{
.host=“app04.xxx.com”;
.port=“80”;
.连接超时=0.7s;
.第一字节超时=30s;
.字节之间\u超时=30s;
.probe={
.url=“/”;
.间隔=5s;
.超时=1s;
.window=5;
.阈值=3;
}
}
后端app05{
.host=“app05.xxx.com”;
.port=“80”;
.连接超时=0.7s;
.第一字节超时=30s;
.字节之间\u超时=30s;
.probe={
.url=“/”;
.间隔=5s;
.超时=1s;
.window=5;
.阈值=3;
}
}
导演应用程序\导演循环赛{
{.backend=app01;}
{.backend=app02;}
{.backend=app03;}
{.backend=app04;}
{.backend=app05;}
}
#acl内部{
#“本地主机”;
#  "127.0.0.1";
#}
acl清除{
“本地主机”;
"192.168.11.0"/24;
}
子vcl_recv{
如果(请求=“清除”){
如果(!client.ip~清除){
错误405“不允许。”;
}
返回(查找);
}
#规范化主机头
# --
if(req.http.Host~“(?i)^(www.xxx.com”){
set req.http.host=“www.xxx.com”;
}
#管理员不需要缓存
# --
if(req.http.Host~“(?i)^(admin.)?xxx.com”){
返回(通行证);
}
#请求/无缓存/不需要缓存
# --
if(req.request==“GET”&&req.url~“^/no cache/”){
返回(通行证);
}
if(req.request==“GET”&&req.url~“^/rss/xxx/”){
返回(通行证);
}
#xx.xxx.com和xxx.com/foro/不需要缓存
# --
如果(req.http.host==“xx.xxx.com”| |(req.http.host==“www.xxx.com”&&req.url~”^/foro/“&&req.http.Cookie~”(?i)(cookieAdmin)”){
返回(通行证);
} 
set req.backend=app\u director;
#如果所有后端都已关闭,请使用匿名缓存页面。
如果(!req.backend.health){
unset req.http.Cookie;
设置req.grace=1h;
}否则{
设置req.grace=30s;
}
#添加X-Forwarded-For标头
# --
如果(请求重新启动==0){
如果(请求http.x-forwarded-for){
设置req.http.X-Forwarded-For=req.http.X-Forwarded-For+“,”+client.ip;
}否则{
设置req.http.X-Forwarded-For=client.ip;
}
}
#根据类型合理地处理请求
# --
如果(请求!=“获取”&&
请求!=“头”&&
请求!=“放置”&&
请求!=“发布”&&
请求!=“跟踪”&&
请求!=“选项”&&
请求!=“删除”){
/*非RFC2616或连接,这很奇怪*/
回流管;
}
#不确定这里可以匹配什么,但它在default.vcl中
# --
如果(请求!=“GET”&&req.request!=“HEAD”){
/*默认情况下,我们只处理GET和HEAD*/
#净化
返回(通行证);
}
#始终为所有用户缓存以下文件类型。
如果(req.url~“(?i)\(png | gif | jpeg | jpg | ico | swf | flv | avi | mov | wmv | css | js | html | htm)(\?[a-z0-9]+)?$){
unset req.http.Cookie;
返回(查找);
}
#正确处理压缩。不同的浏览器发送不同的
#“Accept Encoding”头,尽管它们大部分都支持相同的
#压缩机制。通过将这些压缩头合并到
#一个一致的格式,我们可以减少缓存的大小,并获得更多的点击=
#@see:http://varnish.projects.linpro.no/wiki/FAQ/Compression
if(请求http接受编码){
if(req.http.Accept-Encoding~“gzip”){
#如果浏览器支持它,我们将使用gzip。
设置req.http.Accept-Encoding=“gzip”;
}
else if(req.http.Accept-Encoding~“deflate”){
#接下来,如果支持,请尝试使用deflate。
设置req.http.Accept-Encoding=“deflate”;
}
否则{
#未知算法。请将其删除并发送未编码的。
unset req.http.Accept-Encoding;
}
}
#默认情况下缓存所有请求,覆盖标准Varnish行为
如果(请求==“获取”| |请求==“头部”){
/*默认情况下,我们只处理GET和HEAD*/
unset req.http.Cookie;
返回(查找);
}
#如果在这一点后面还有cookie,请不要缓存
#或者这更容易保存在上面的cookie删除中?
# --
if(req.http.Authorization | | req.http.Cookie){
/*默认情况下不可缓存*/
返回(通行证);
}
#如果我们到了这里,试试缓存
# --
返回(查找);
}
子vcl_管{
回流管;
}
副vcl_通行证{
返回(通行证);
}
子vcl_散列{
#在缓存哈希中包含cookie。
#此检查是不必要的,因为我们已经传递了所有cookie。
#if(req.http.Cookie){
##set req.hash+=req.http.Cookie;
#哈希_数据(req.http.Cookie);
#}
}
子vcl_命中{
如果(请求=“清除”){
设置obj.ttl=0s;
错误200“已清除”;
}
}
子vcl_未命中{
如果(请求=“清除”){
错误404“不在缓存中”;
}
}
子vcl_取数{
#删除所有cookies
#unset beresp.http.set-cookie;
#缓存12小时
#设置beresp.ttl=2h;
#不允许静态文件设置cookie。
如果(req.url~)(
backend app01 {
  .host = "app01.xxx.com";
  .port = "80";
  .connect_timeout = 0.7s;
  .first_byte_timeout = 30s;
  .between_bytes_timeout = 30s;
  .probe = {
    .url = "/";
    .interval = 5s;
    .timeout = 1s;
    .window = 5;
    .threshold = 3;
  }
}

backend app02 {
  .host = "app02.xxx.com";
  .port = "80";
  .connect_timeout = 0.7s;
  .first_byte_timeout = 30s;
  .between_bytes_timeout = 30s;
  .probe = {
    .url = "/";
    .interval = 5s;
    .timeout = 1s;
    .window = 5;
    .threshold = 3;
  }
}

backend app03 {
  .host = "app03.xxx.com";
  .port = "80";
  .connect_timeout = 0.7s;
  .first_byte_timeout = 30s;
  .between_bytes_timeout = 30s;
  .probe = {
    .url = "/";
    .interval = 5s;
    .timeout = 1s;
    .window = 5;
    .threshold = 3;
  }
}

backend app04 {
  .host = "app04.xxx.com";
  .port = "80";
  .connect_timeout = 0.7s;
  .first_byte_timeout = 30s;
  .between_bytes_timeout = 30s;
  .probe = {
    .url = "/";
    .interval = 5s;
    .timeout = 1s;
    .window = 5;
    .threshold = 3;
  }
}

backend app05 {
  .host = "app05.xxx.com";
  .port = "80";
  .connect_timeout = 0.7s;
  .first_byte_timeout = 30s;
  .between_bytes_timeout = 30s;
  .probe = {
    .url = "/";
    .interval = 5s;
    .timeout = 1s;
    .window = 5;
    .threshold = 3;
  }
}

director app_director round-robin {
  { .backend = app01; }
  { .backend = app02; }
  { .backend = app03; }
  { .backend = app04; }
  { .backend = app05; }   
}

#acl internal {
#  "localhost";
#  "127.0.0.1";
#}

acl purge {
        "localhost";
        "192.168.11.0"/24;
}

sub vcl_recv {

  if (req.request == "PURGE") {
    if (!client.ip ~ purge) {
      error 405 "Not allowed.";
    }
    return (lookup);
  }

  # Normalize the host header
  # --
  if (req.http.Host ~ "(?i)^(www.)?xxx.com") {
    set req.http.host = "www.xxx.com";
  }

  # Admin needs no cache
  # --
  if (req.http.Host ~ "(?i)^(admin.)?xxx.com") {
    return (pass);
  }

  # Requests to /no-cache/ needs no cache
  # --
  if (req.request == "GET" && req.url ~ "^/no-cache/") {
    return (pass);
  }
  if (req.request == "GET" && req.url ~ "^/rss/xxx/") {
    return (pass);
  }

  # xx.xxx.com and xxx.com/foro/ needs no cache
  # --
  if (req.http.host == "xx.xxx.com" || (req.http.host == "www.xxx.com" && req.url ~ "^/foro/" && req.http.Cookie ~ "(?i)(cookieAdmin)") ) {
    return (pass);
  } 

  set req.backend = app_director;

  # Use anonymous, cached pages if all backends are down.
  if (! req.backend.healthy) {
    unset req.http.Cookie;
    set req.grace = 1h;
  } else {
    set req.grace = 30s;
  }

  # Add the X-Forwarded-For header
  # --
  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;
    }
  }

  # Sanely handle the request based on the type
  # --
  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);
  }

  # Not sure what could match here, but it's in the default.vcl
  # --
  if (req.request != "GET" && req.request != "HEAD") {
    /* We only deal with GET and HEAD by default */
    # PURGE
    return (pass);
  }

  # Always cache the following file types for all users.
  if (req.url ~ "(?i)\.(png|gif|jpeg|jpg|ico|swf|flv|avi|mov|wmv|css|js|html|htm)(\?[a-z0-9]+)?$") {
    unset req.http.Cookie;
    return (lookup);
  }

  # Handle compression correctly. Different browsers send different
  # "Accept-Encoding" headers, even though they mostly all support the same
  # compression mechanisms. By consolidating these compression headers into
  # a consistent format, we can reduce the size of the cache and get more hits.=
  # @see: http:// varnish.projects.linpro.no/wiki/FAQ/Compression
  if (req.http.Accept-Encoding) {
    if (req.http.Accept-Encoding ~ "gzip") {
      # If the browser supports it, we'll use gzip.
      set req.http.Accept-Encoding = "gzip";
    }
    else if (req.http.Accept-Encoding ~ "deflate") {
      # Next, try deflate if it is supported.
      set req.http.Accept-Encoding = "deflate";
    }
    else {
      # Unknown algorithm. Remove it and send unencoded.
      unset req.http.Accept-Encoding;
    }
  }

  # Cache all requests by default, overriding the standard Varnish behavior
  if (req.request == "GET" || req.request == "HEAD") {
    /* We only deal with GET and HEAD by default */
    unset req.http.Cookie;
    return (lookup);
  }

  # If there's a cookie left aft this point do not cache
  # or is this easier to keep in the cookie deletion above?
  # --
  if (req.http.Authorization || req.http.Cookie) {
    /* Not cacheable by default */
    return (pass);
  }

  # If we get here, try the cache
  # --
  return (lookup);

}



sub vcl_pipe {
  return (pipe);
}

sub vcl_pass {
  return (pass);
}

sub vcl_hash {
  # Include cookie in cache hash.
  # This check is unnecessary because we already pass on all cookies.
  #if (req.http.Cookie) {
  #  #set req.hash += req.http.Cookie;
  #  hash_data(req.http.Cookie);
  #}
}

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_fetch {

  # remove all cookies
  # unset beresp.http.set-cookie;

  # cache for 12 hours
  # set beresp.ttl = 2h;

  # Don't allow static files to set cookies.
  if (req.url ~ "(?i)\.(png|gif|jpeg|jpg|ico|swf|css|js|html|htm)(\?[a-z0-9]+)?$") {
    unset beresp.http.set-cookie;
    set beresp.ttl = 12h;
  } else {
    unset beresp.http.set-cookie;
    set beresp.ttl = 30m;
  }

  # If the backend server doesn't return properly, don't send another connection to it
  # for 60s and try another backend via restart.
  #
  # https://www.varnish-cache.org/docs/trunk/tutorial/handling_misbehaving_servers.html
  # --
  if(beresp.status == 500) {
    set beresp.saintmode = 5m;
    if (req.request != "POST") {
      return(restart);
    } else {
      error 500 "Failed";
    }
  }

  # Allow items to be stale if needed.
  set beresp.grace = 1h;

}

sub vcl_deliver {
 # if (resp.http.magicmarker) {
 #   unset resp.http.magicmarker;
 #   set resp.http.age = "0";
 # }

  if (obj.hits > 0) {
    set resp.http.X-Cache = "HIT";
  } else {
    set resp.http.X-Cache = "MISS";
  }
  return (deliver);
}

# In the event of an error, show friendlier messages.
sub vcl_error {
  # Otherwise redirect to the homepage, which will likely be in the cache.
  set obj.http.Content-Type = "text/html; charset=utf-8";
  synthetic {"
<html>
<head>
  <title>Page Unavailable</title>
  <style>
    body { background: #303030; text-align: center; color: white; }
    #page { border: 1px solid #CCC; width: 500px; margin: 100px auto 0; padding: 30px; background: #323232; }
    a, a:link, a:visited { color: #CCC; }
    .error { color: #222; }
  </style>
</head>
<body onload="setTimeout(function() { window.location = '/' }, 5000)">
  <div id="page">
    <h1 class="title">Page Unavailable</h1>
    <p>The page you requested is temporarily unavailable.</p>
    <p>We're redirecting you to the <a href="/">homepage</a> in 5 seconds.</p>
    <div class="error">(Error "} + obj.status + " " + obj.response + {")</div>
  </div>
</body>
</html>
"};
  return (deliver);
}

sub vcl_init {
  return (ok);
}

sub vcl_fini {
  return (ok);
}