ESI include does not work until I reload page

rafael rafaelcrocha at gmail.com
Fri Mar 4 17:50:33 CET 2011


Hello everyone.

I am using varnish to cache my Plone site, with xdv.

I have the following configuration: nginx - varnish - nginx (apply xdv
transf) - haproxy - plone.

My problem is that the first time I open a page, my esi includes are not
interpreted.. I get a blank content, and in firebug I can see the esi
statement.


<esi:include src="http://inverta.org:80/jornal/repositorio/destaque/?;filter_xpath=//*[@id=%22content%22]/div[1]/*"></esi:include>


(If I ask firefox to show me the source, it makes a new request, so the
source displayed has the correct replacements).

If I reload the page, or open it in a new tab everything works
perfectly. The problem is only the first time a browser open the pages.
If I close and reopen the browser, the first time the page is opened,
the error appears again..





My varnish.vcl config:

# This is a basic VCL configuration file for varnish.  See the vcl(7)
# man page for details on VCL syntax and semantics.

backend backend_0 {
    .host = "127.0.0.1";
    .port = "1010";
    .connect_timeout = 0.4s;
    .first_byte_timeout = 300s;
    .between_bytes_timeout = 60s;
}


acl purge {
    "localhost";
    "127.0.0.1";

}

sub vcl_recv {
    set req.grace = 120s;
    set req.backend = backend_0;
   
    if (req.request == "PURGE") {
        if (!client.ip ~ purge) {
            error 405 "Not allowed.";
        }
        lookup;
    }

    if (req.request != "GET" &&
        req.request != "HEAD" &&
        req.request != "PUT" &&
        req.request != "POST" &&
        req.request != "TRACE" &&
        req.request != "OPTIONS" &&
        req.request != "DELETE") {
        /* Non-RFC2616 or CONNECT which is weird. */
        pipe;
    }

    if (req.request != "GET" && req.request != "HEAD") {
        /* We only deal with GET and HEAD by default */
        pass;
    }

    if (req.http.If-None-Match) {
        pass;
    }

    if (req.url ~ "createObject") {
        pass;
    }

    remove req.http.Accept-Encoding;

    lookup;
}

sub vcl_pipe {
    # This is not necessary if you do not do any request rewriting.
    set req.http.connection = "close";
    set bereq.http.connection = "close";
}

sub vcl_hit {
    if (req.request == "PURGE") {
        purge_url(req.url);
        error 200 "Purged";
    }

    if (!obj.cacheable) {
        pass;
    }
}

sub vcl_miss {
    if (req.request == "PURGE") {
        error 404 "Not in cache";
    }

}


sub vcl_fetch {
      set obj.grace = 120s;
    if (!obj.cacheable) {
        pass;
    }
    if (obj.http.Set-Cookie) {
        pass;
    }
    if (obj.http.Cache-Control ~ "(private|no-cache|no-store)") {
        pass;
    }
    if (req.http.Authorization && !obj.http.Cache-Control ~ "public") {
        pass;
    }
    if (obj.http.Content-Type ~ "text/html") {
        esi;
    }
}

sub vcl_hash {
    set req.hash += req.url;
    set req.hash += req.http.host;

    if (req.http.Accept-Encoding ~ "gzip") {
        set req.hash += "gzip";
    }
    else if (req.http.Accept-Encoding ~ "deflate") {
        set req.hash += "deflate";
    }
}



Thanks for all,

Rafael







More information about the varnish-misc mailing list