【问题标题】:Varnish 3.0 returns 503 errorVarnish 3.0 返回 503 错误
【发布时间】:2012-06-16 16:34:55
【问题描述】:

我正在使用 varnish 来缓存我网站的内容。它按预期工作,但有一个问题。它随机返回一个 503 错误,这真的很奇怪,因为应用程序服务器正常,负载低于 0.8,数据库服务器也正常。这是我的配置的一部分:

backend app05 {
  .host = "app05.site.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; }   
}

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|mp4|flv)(\?[a-z0-9]+)?$") {
    unset beresp.http.set-cookie;
    set beresp.ttl = 12h;
  } else {
    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;

}

我是否还必须添加到 if beresp.status == 503?

【问题讨论】:

  • 从配置文件中很难判断。你试过用 varnish_log 检查日志吗?

标签: caching varnish varnish-vcl


【解决方案1】:

我已经解决了这个问题。我只需要增加连接过期的时间并检查重新连接的次数。这是我添加的行:

host = "app01.site.com";
  .port = "80";
  .connect_timeout = 1.5s;
  .first_byte_timeout = 45s;
  .between_bytes_timeout = 30s;

if (req.restarts > 3) {
  set beresp.saintmode = 5m;
}

【讨论】:

  • 会帮助提及您在哪些子例程中添加了 saintmode。
  • @JoeYahchouchi 这是 6 年前的事,所以现在我不记得了……但也许它在主要配置下。正如您在问题中看到的那样,第 2 到第 6 行与答案中的行相匹配,因此可能在这些行之后添加了 saintmode... 抱歉此时没有更好的答案:(
  • 我认为他们摆脱了这个概念。现在设置任何类型的宽限都会自动发送陈旧的响应并尝试获取新的响应,如果新的响应失败,它会继续发送陈旧的......
  • @JoeYahchouchi 你有参考吗?也许您可以编辑答案添加更多信息。老实说,自从我停止使用它已经有好几年了,所以我对它真的很生疏……否则我会自己做。
  • 很遗憾我没有。
猜你喜欢
  • 2019-12-09
  • 2020-06-03
  • 2013-04-12
  • 2013-12-03
  • 2016-06-19
  • 2015-03-27
  • 1970-01-01
  • 2016-01-17
  • 2011-02-25
相关资源
最近更新 更多