Weird backend selection policy

Sergei Kononov sergei.kononov at gmail.com
Wed Mar 25 13:40:37 CET 2009


Hi,

I noticed weird behavior of backend selection. Some request goes to
backend which is not suitable for them, as result I getting 404 or 500
errors, but I noticed that removing "lookup" in end of vcl_recv can
fix that problem, at least this problem does not occur so frequently
after that.

Here is my vcl_recv:

sub vcl_recv {
   set req.http.X-Cacheable = "true";
   set req.http.X-Forwarded-For=client.ip;
   set req.backend = default;

   if ( req.url ~ "^/api/.*" ) {
      set req.backend = b2;
      set req.url = regsub(req.url, "^/api/", "/")
      set req.http.X-Cacheable = "false";
      pipe;
   }

   if ( req.url ~ "^/rpc.*" ) {
      set req.backend = rpc;
      set req.http.X-Cacheable = "false";
      pipe;
   }

   if ( req.url ~ "^/flv/.*" || req.url ~ "^/images.(128|320)/.*" ) {
      set req.backend = media;
   }

   if ( req.url ~ "^/media.hq.flv/.*" ) {
      pipe;
   }

   if ( req.url ~ "^/emit/.*" ) {
      set req.backend = default;
      pipe;
   }

   if (req.http.Cache-Control ~ "no-cache") {
    pass;
   }

 #if comment out lookup keyword varnish start to handle requests wierdly
 #lookup
 }

And here is my vcl_fetch(not sure that it intended in this issue):
sub vcl_fetch {
 if (obj.http.Pragma ~ "no-cache" || obj.http.Cache-Control ~
"no-cache" || obj.http.Cache-Control ~ "private") {
   pass;
 }

 if (! req.http.X-Cacheable ~ "true" ) {
   set obj.http.Cache-Control = "no-cache";
   set obj.http.Expires = "Tue, 01 Jan 2000 00:00:01 GMT";
   pass;
 }

 set obj.ttl = 3600s;

}

I suppose that there is some error in vlc_ subs, but they seems ok.

-- 
Sergei Kononov



More information about the varnish-misc mailing list