开发者

Varnish round robin director with backend virtual hosts

开发者 https://www.devze.com 2023-04-03 11:54 出处:网络
I\'ve been trying like mad to figure out the VCL for how to do this and am beginning to think it\'s not possible. I have several backend app servers that serve a variety of different hosts. I need var

I've been trying like mad to figure out the VCL for how to do this and am beginning to think it's not possible. I have several backend app servers that serve a variety of different hosts. I need varni开发者_如何转开发sh 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). Is there any way around this? I'd love to just point the cache miss to an IP and leave the request host intact.

Here's what I have now:

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...

This is my first StackOverflow question so please let me know if I neglected to mention something important! Thanks.


Here is what I actually got to work. I credit ivy because his answer is technically correct, and because one of the problems was my host (they were blocking ports that prevented my normal web requests from getting through). The real problem I was having was that heartbeat messages had no host info, so the vhost couldn't route them correctly. Here's a sample backend definition with a probe that crafts a completely custom request:

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;
  }
}


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 is not a hostname, it's a back-end definition with an ip-address. You're defining some routing logic in your vcl file (to which backend a request is proxied), but you're not changing the hostname in the request. What you're asking for (keep the hostname the same) is the default behavior.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号