gpt4 book ai didi

具有后端虚拟主机的Varnish Round Robin Director

转载 作者:行者123 更新时间:2023-12-03 17:47:17 24 4
gpt4 key购买 nike

我一直在试图像疯了一样弄清楚如何做到这一点的VCL和我开始认为这是不可能的。我有几个后端应用程序服务器,可以服务各种不同的主机。我需要使用 Varnish 来缓存任何主机的页面,并将缺少缓存的请求发送到具有请求中原始主机信息的应用程序服务器(“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问题,所以如果我忽略提及重要事项,请告诉我!谢谢。

最佳答案

I need varnish to cache pages for any host and send requests that miss the cache to the app servers with the original host info in the request ("www.site.com"). However, all the VCL examples seem to require me to use a specific host name for my backend server ("backend1" for example)



backend1不是主机名,它是带有ip地址的后端定义。您正在vcl文件中定义了一些路由逻辑(将请求后端转发到该文件),但是您没有在请求中更改主机名。您要求的(保持主机名相同)是默认行为。

关于具有后端虚拟主机的Varnish Round Robin Director,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7335406/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com