Varnish 504 网关超时

标签 varnish varnish-vcl

我有 2 台 Varnish 服务器位于 NY2 区域的 digital ocean 中。我有两个网络服务器位于 Amazon EC2 us-east-1b 中。

Varnish 的版本为 3.05,而 apache 在 Web 服务器上运行的版本为 2.4.6。我发现,在正常加载页面之前,每个加载的页面都会出现“504 网关超时”错误。有时,如果您第二次点击该页面,它会再次给出超时错误。

这是一个烦人的错误,我想尝试纠正。我尝试通过在 Varnish 配置中将超时设置为非常高来解决这个问题。这阻止了我收到的 503 错误,但现在 504 错误是主要问题。

我有一个非常简单的 Varnish VCL 文件。这是:

backend web1 {
  .host = "10.10.10.25";
  .port = "80";
  .connect_timeout = 1200s;
  .first_byte_timeout = 1200s;
  .between_bytes_timeout = 1200s;
  .max_connections = 70;
  .probe = {
  .request =
   "GET /healthcheck.php HTTP/1.1"
   "Host: wiki.example.com"
   "Connection: close";
   .interval = 10m;
   .timeout = 60s;
   .window = 3;
   .threshold = 2;
   }
}

backend web2 {
  .host = "10.10.10.26";
  .port = "80";
  .connect_timeout = 1200s;
  .first_byte_timeout = 1200s;
  .between_bytes_timeout = 1200s;
  .max_connections = 70;
  .probe = {
  .request =
   "GET /healthcheck.php HTTP/1.1"
   "Host: wiki.example.com"
   "Connection: close";
   .interval = 10m;
   .timeout = 60s;
   .window = 3;
   .threshold = 2;
   }
}


director www round-robin {
  { .backend = web1;   }
  { .backend = web2;  }
 }


sub vcl_recv {

    if (req.url ~ "&action=submit($|/)") {
        return (pass);
    }

    set req.backend = www;
    return (lookup);
}

sub vcl_fetch {
      set beresp.ttl = 3600s;
      set beresp.grace = 4h;
      return (deliver);
}



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

这是当页面出现 504 错误时我在 varnish 日志中遇到的错误:

   10 TxHeader     c Age: 1
   10 TxHeader     c Via: 1.1 varnish
   10 TxHeader     c Connection: close
   10 TxHeader     c X-Cache: MISS
   10 Debug        c Write error, retval = -1, len = 75311, errno = Connection reset by peer
   10 ReqEnd       c 1481957120 1436230882.856483936 1436230941.208484650 0.000118494 58.351872206 0.000128508
   10 StatSess     c 54.88.194.254 52474 58 1 1 0 0 1 565 74746

我已经检查过我可以在发生此错误后 curl 运行状况检查文件,而且似乎可以:

[root@varnish1:/etc/varnish] #curl http://wiki.example.com/healthcheck.php
good

这是一个奇怪的设置,但我们需要几周时间才能批准在 EC2 中设置 Varnish 。这是我继承的设置,需要尝试使其在接下来的几周内发挥作用。

非常感谢您提供的任何帮助和见解。

最佳答案

“errno = 连接被对等方重置”

对等方正在重置连接。这在 Varnish 中不会发生。去调试对等点。

关于 Varnish 504 网关超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31258150/

相关文章:

varnish - 在Varnish 4中 'synthetic'设置了哪个变量?

caching - 如何访问 Varnish 管理区域?

varnish - Varnish 默认缓存 404s 吗?

regex - 剥离选择查询字符串属性/值对,以便 Varnish 不会因它们而改变缓存

caching - Varnish 排除网址

java - 限制 Varnish 客户端等待时间,而不是后端时间

varnish - 从缓存发出 Varnish 服务请求(cookies被清除)

varnish4 与 varnish3 - 优雅行为

reverse-proxy - 公司代理后面的 Varnish 或鱿鱼反向代理

Magento 多语言商店与 Varnish