0

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

4

2 回答 2

3

这是我实际工作的内容。我相信常春藤,因为他的回答在技术上是正确的,并且因为问题之一是我的主机(它们阻塞了阻止我正常 Web 请求通过的端口)。我遇到的真正问题是心跳消息没有主机信息,因此虚拟主机无法正确路由它们。这是一个示例后端定义,其中包含一个制作完全自定义请求的探针:

backend app1 {
  .host = "192.168.1.11";
  .port = "80";
  .probe = {
            .request = "GET /heartbeat HTTP/1.1"
                       "Host: something.com"
                       "Connection: close"
                       "Accept-Encoding: text/html" ;
            .interval = 15s;
            .timeout = 2s;
            .window = 5;
            .threshold = 3;
  }
}
于 2011-09-10T04:13:31.497 回答
0

我需要清漆来缓存任何主机的页面,并将错过缓存的请求发送到应用服务器,并使用请求中的原始主机信息(“www.site.com”)。但是,所有 VCL 示例似乎都要求我为我的后端服务器使用特定的主机名(例如“backend1”)

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

于 2011-09-08T20:52:49.907 回答