Handling 304 and header refresh

Daniel Rodriguez coolbomb at gmail.com
Fri Nov 27 14:34:44 CET 2009


Hi,

I'm having a problem with a varnish caching implementation in our sites.

We have some big and heavy loaded sites, and one of the things we are
used to do, is to return a 304 from an object but with some
modifications to the object headers. This works cool with our current
caching systems (the ones that are going to be replaced with varnish).

Example:

http://www.foo.com/varnish.jpg

That image never changes so our apache server will always returns 304.
In some situations we need to change one of the headers of the object
(changing the max age is one of the things we usually do).

But if we do that with varnish all our fetches after changing the
headers end up on our backbends.

Am i missing something?

My config and a segment of the logs after the headers being refreshed:

backend default {
        .host = "192.168.9.158";
	.port = "80";
}

acl purge {
        "localhost";
        "192.168.90.14";
        "192.168.90.34";
}
sub vcl_recv {
   set req.http.X-Forwarded-For = client.ip;
   if (req.request != "GET" &&
      req.request != "HEAD" &&
      req.request != "PUT" &&
      req.request != "POST" &&
      req.request != "PURGE" &&
        /* Non-RFC2616 or CONNECT which is weird. */
        return (pipe);
   }
   set req.grace = 2m;
   if (req.http.Accept-Encoding) {
      if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$") {
             remove req.http.Accept-Encoding;
      } elsif (req.http.Accept-Encoding ~ "gzip") {
         set req.http.Accept-Encoding = "gzip";
      } elsif (req.http.Accept-Encoding ~ "deflate") {
         set req.http.Accept-Encoding = "deflate";
      } else {
         # No se conoce el algoritmo
        remove req.http.Accept-Encoding;
      }
   }
   if (req.request == "PURGE") {
      if (!client.ip ~ purge) {
         error 405 "Not allowed.";
      }
      purge("req.url == " req.url);
   }
   if (req.http.Authorization) {
       return (pass);
   }
   return(lookup);
}

sub vcl_fetch {
    set obj.grace = 2m;
    if(obj.http.Pragma ~ "no-cache" || obj.http.Cache-Control ~
"no-cache" || obj.http.Cache-Control ~ "private" ||
obj.http.Cache-Control ~ "max-age=0" || obj.http.Cache-Control ~
"must-revalidate" || obj.http.Cache-Control ~ "private" ) {
       pass;
    }
    if (!obj.cacheable) {
        return (pass);
    }
    if (obj.http.Set-Cookie) {
        return (pass);
    }
    set obj.prefetch =  -3s;
    if (req.http.Authorization && !obj.http.Cache-Control ~ "public") {
       pass;
    }
    return (deliver);
}



   12 ReqStart     c 192.168.90.41 44056 345093438
   12 RxRequest    c GET
   12 RxURL        c /test/prueba.php
   12 RxProtocol   c HTTP/1.1
   12 RxHeader     c Host: www.foo.com
   12 RxHeader     c User-Agent: Mozilla/5.0 (X11; U; Linux i686;
en-US; rv:1.9.0.3) Gecko/2008092816 Iceweasel/3.0.3 (Debian-3.0.3-3)
   12 RxHeader     c Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
   12 RxHeader     c Accept-Language: en-us,en;q=0.5
   12 RxHeader     c Accept-Encoding: gzip,deflate
   12 RxHeader     c Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
   12 RxHeader     c Keep-Alive: 300
   12 RxHeader     c Connection: keep-alive
   12 RxHeader     c Cookie: foo.comGlobal=0; cUser=nouser
   12 VCL_call     c recv
   12 VCL_return   c lookup
   12 VCL_call     c hash
   12 VCL_return   c hash
   12 HitPass      c 345093401
   12 VCL_call     c pass
   12 VCL_return   c pass
   13 BackendOpen  b default 192.168.55.18 13822 192.168.9.158 80
   12 Backend      c 13 default default
   13 TxRequest    b GET
   13 TxURL        b /test/prueba.php
   13 TxProtocol   b HTTP/1.1
   13 TxHeader     b Host: www.foo.com.com
   13 TxHeader     b User-Agent: Mozilla/5.0 (X11; U; Linux i686;
en-US; rv:1.9.0.3) Gecko/2008092816 Iceweasel/3.0.3 (Debian-3.0.3-3)
   13 TxHeader     b Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
   13 TxHeader     b Accept-Language: en-us,en;q=0.5
   13 TxHeader     b Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
   13 TxHeader     b Cookie: foo.comGlobal=0; cUser=nouser
   13 TxHeader     b Accept-Encoding: gzip
   13 TxHeader     b X-Varnish: 345093438
   13 TxHeader     b X-Forwarded-For: 192.168.90.41
   13 RxProtocol   b HTTP/1.1
   13 RxStatus     b 304
   13 RxResponse   b Not Modified
   13 RxHeader     b Date: Mon, 23 Nov 2009 17:11:37 GMT
   13 RxHeader     b Server: Apache
   13 RxHeader     b Connection: close
   13 RxHeader     b Cache-control: max-age=20
   12 ObjProtocol  c HTTP/1.1
   12 ObjStatus    c 304
   12 ObjResponse  c Not Modified
   12 ObjHeader    c Date: Mon, 23 Nov 2009 17:11:37 GMT
   12 ObjHeader    c Server: Apache
   12 ObjHeader    c Cache-control: max-age=20
   13 BackendClose b default
   12 TTL          c 345093438 RFC 20 1258996298 0 0 20 0
   12 VCL_call     c fetch
   12 VCL_return   c pass
   12 Length       c 0
   12 VCL_call     c deliver
   12 VCL_return   c deliver
   12 TxProtocol   c HTTP/1.1
   12 TxStatus     c 304
   12 TxResponse   c Not Modified
   12 TxHeader     c Server: Apache
   12 TxHeader     c Cache-control: max-age=20
   12 TxHeader     c Content-Length: 0
   12 TxHeader     c Date: Mon, 23 Nov 2009 17:11:38 GMT
   12 TxHeader     c X-Varnish: 345093438
   12 TxHeader     c Age: 0
   12 TxHeader     c Via: 1.1 varnish
   12 TxHeader     c Connection: keep-alive
   12 ReqEnd       c 345093438 1258996298.242152929
1258996298.246277332 0.538141012 0.003986359 0.000138044
   12 Debug        c "herding"

Thank you!



More information about the varnish-misc mailing list