Varnish and language cookie

Yann Malet yann.malet at gmail.com
Tue Feb 23 16:47:51 CET 2010


Hello,

I am having hard time to to cache a multilingual web site. Vanish listen on
port 80 and proxy the request to a multilingual django cms what I would like
to do is to cache the pages per language and serve them from the
cache. Unfortunately so far I have not been able to get this working and
varnish keep on fetching th pages from the cms.

I am going to add below all the information I think useful do not hesitate
to let me know if you need more info ?

Here it is my configuration :
sub vcl_recv {
    # clean out requests sent via curls -X mode and LWP
    # http://varnish.projects.linpro.no/wiki/VCLExampleNormalizingReqUrl
    if (req.url ~ "^http://") {
        set req.url = regsub(req.url, "http://[^/]*", "");
    }
    # Set the backend based on the subdomain name
    if (req.http.host == "static.gwadeloop.com") {
        set req.backend = static;
    }
    if (req.http.host == "dev.gwadeloop.com") {
        set req.backend = django;
        # Add a trailing slash if missing
        if ((req.url ~ "[^\]$") && (! (req.url ~ "^/media/"))) {
            set req.url = req.url "/";
        }
    }
    if (req.http.Cookie) {
        # removes all cookies named __utm? (utma, utmb...)  -- Google
Analytics
        set req.http.Cookie = regsuball(req.http.Cookie, "(^|; )
*__utm.=[^;]+;? *", "\1");
        if (req.http.Cookie == "") {
            remove req.http.Cookie;
        }
   }
     if (req.http.Cookie ~ "django_language=") {
         set req.http.X-Varnish-Language =
             regsub(req.http.Cookie, "django_language=([a-z]{2})", "\1");
     }
}
-------------------------
sub vcl_hash {
    set req.hash += req.url;
    if (req.http.host) {
        set req.hash += req.http.host;
    } else {
        set req.hash += server.ip;
    }
    set req.hash += req.http.X-Varnish-Language;
    return (hash);
}

 -------------------------

here it is the information outputed by varnishlog when I try to access the
same page twice:
http://dpaste.com/163624/

I would be glad if someone could point me what I am doing wrong here.
Regards,
--yml
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20100223/ee437721/attachment-0001.html>


More information about the varnish-misc mailing list