【问题标题】:Varnish round robin director with backend virtual hosts带有后端虚拟主机的 Varnish 循环导向器
【发布时间】:2011-09-10 12:13:31
【问题描述】:

我一直在疯狂地尝试找出 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 问题,所以如果我忽略了重要的事情,请告诉我!谢谢。

【问题讨论】:

    标签: varnish


    【解决方案1】:

    这是我实际要做的工作。我相信常春藤,因为他的回答在技术上是正确的,并且因为问题之一是我的主机(它们阻塞了阻止我正常 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;
      }
    }
    

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      • 这在技术上是一个正确的答案,常春藤。然而,最终的问题是我的探测请求上没有任何主机信息,所以 nginx 不知道如何将心跳 GET 请求定向到正确的虚拟主机。我通过手动执行探测请求解决了这个问题,我将在另一个答案中提出。
      猜你喜欢
      • 2015-05-19
      • 2019-03-01
      • 2012-04-06
      • 2016-10-16
      • 2016-12-10
      • 2010-10-07
      • 2012-08-17
      • 2012-08-18
      • 2015-01-31
      相关资源
      最近更新 更多