Question

J'ai essayé comme un fou pour déterminer la VCL pour savoir comment faire cela et je commence à penser qu'il est impossible. J'ai plusieurs serveurs d'applications back-end qui servent une variété de différents hôtes. J'ai besoin de vernis pour les pages de cache pour toutes les demandes d'accueil et d'envoyer le cache qui manquent aux serveurs d'applications avec les informations d'hôte d'origine dans la demande ( « www.site.com »). Cependant, tous les exemples VCL semblent me demander d'utiliser un nom d'hôte spécifique pour mon serveur principal (le « backend1 », par exemple). Y at-il moyen de contourner cela? J'aimerais souligner que le manque de cache à un IP et laisser l'hôte demande intacte.

Voici ce que j'ai maintenant:

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

Ceci est ma première question StackOverflow donc s'il vous plaît laissez-moi savoir si j'oublié de mentionner quelque chose d'important! Merci.

Était-ce utile?

La solution

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.

Autres conseils

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;
  }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top