我一直在疯狂地试图弄清楚如何做到这一点的 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);
}
}
ETC...
这是我的第一个 StackOverflow 问题,所以如果我忽略了重要的事情,请告诉我!谢谢。