我有 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/