我一直想疯了想弄清楚如何做到这一点的VCL,我开始认为这是不可能的。我有几台后端应用程序服务器可以服务于各种不同的主机。我需要清漆缓存任何主机的页面,并发送错过缓存的请求到具有请求中原始主机信息的应用程序服务器(“www.site.com”)。但是,所有的VCL示例似乎都要求我为后端服务器使用特定的主机名(例如,“backend1”)。有没有办法解决?我很乐意将缓存未命中指向IP,并保持请求主机完好无损。清漆循环主管与后端虚拟主机
这是我现在有:
backend app1 {
.host = "192.168.1.11";
.probe = {
.url = "/heartbeat";
.interval = 5s;
.timeout = 1 s;
.window = 5;
.threshold = 3;
}
}
backend app2 {
.host = "192.168.1.12";
.probe = {
.url = "/heartbeat";
.interval = 5s;
.timeout = 1 s;
.window = 5;
.threshold = 3;
}
}
director pwms_t247 round-robin {
{
.backend = app1;
}
{
.backend = app2;
}
}
sub vcl_recv {
# pass on any requests that varnish should not handle
if (req.request != "HEAD" && req.request != "GET" && req.request != "BAN") {
return (pass);
}
# pass requests to the backend if they have a no-cache header or cookie
if (req.http.x-varnish-no-cache == "true" || (req.http.cookie && req.http.cookie ~ "x-varnish-no-cache=true")) {
return (pass);
}
# Lookup requests that we know should be cached
if (req.url ~ ".*") {
# Clear cookie and authorization headers, set grace time, lookup in the cache
unset req.http.Cookie;
unset req.http.Authorization;
return(lookup);
}
}
等等
这是我的第一个问题的StackOverflow,所以请让我知道如果我忘了提及一些重要的东西!谢谢。
这在技术上是正确答案,常春藤。然而,最终导致问题的是我的探测请求没有任何主机信息,因此nginx不知道如何将心跳GET请求指向正确的虚拟主机。我通过手动完成探测请求解决了这个问题,我将在另一个答案中提出。 – jeremy6d