Varnish 返回错误的后端

Varnish 返回错误的后端

遇到 Varnish 返回错误后端的问题。我在 Apache 的虚拟主机上有几个后端监听端口 8080 到 8095。我按如下方式配置了 Varnish 后端:

acl purge {
    "localhost";
    "192.168.0.1";
}

backend default {
    .host = "192.168.0.1";
    .port = "8094";
    .connect_timeout =  20s; #600s;
    .first_byte_timeout = 20s; #600s;
    .between_bytes_timeout = 20s; #600s;
}

backend default_mobile {
    .host = "192.168.0.1";
    .port = "8093";
    .connect_timeout =  20s; #600s;
    .first_byte_timeout = 20s; #600s;
    .between_bytes_timeout = 20s; #600s;
}

backend secondary {
    .host = "192.168.0.1";
    .port = "8082";
    .connect_timeout =  20s; #600s;
    .first_byte_timeout = 20s; #600s;
    .between_bytes_timeout = 20s; #600s;
}

backend secondary_mobile {
    .host = "192.168.0.1";
    .port = "8083";
    .connect_timeout =  20s; #600s;
    .first_byte_timeout = 20s; #600s;
    .between_bytes_timeout = 20s; #600s;
}

在大多数情况下,这种方法效果很好,但一段时间后(几个小时),我们会收到用户在错误 URL 下看到错误网站的报告。例如,他们会访问 www.example.com 并从 secondary_mobile 后端获取页面。错误返回的始终是同一个后端,浏览器中的 URL 将显示目标网站 (www.example.com)。我们在 Apache 中没有任何类型的重定向,所以我不确定它是如何变得混乱的。下面是我设置后端的示例:

....
if ( req.http.host ~ "example.com$" ) { 
    set req.backend = default;
    set req.http.host = "www.example.com";
} else if ( req.http.host ~ "^(www.)?example2.com$" ) { 
    set req.backend = secondary;
    set req.http.host = "www.example2.com";
} else if ( req.http.host ~ "^(m.)?example2.com$" ) { 
    set req.backend = secondary_mobile;
    set req.http.host = "m.example2.com";
....

我以为手动指定主机就足够了,但显然不是。Varnish 文档也没有太多关于这个主题的内容。

相关内容