Caching cookies with Varnish 4
Raymond Gonzalez
raygo22 at gmail.com
Thu May 14 00:50:18 CEST 2015
This is my current vcl, can you see what am I doing wrong? Thanks!:
sub vcl_recv {
# Happens before we check if we have this in cache already.
#
# Typically you clean up the request here, removing cookies you don't
need,
# rewriting the request, etc.
if (req.method != "GET" &&
req.method != "HEAD" &&
req.method != "PUT" &&
req.method != "POST" &&
req.method != "TRACE" &&
req.method != "OPTIONS" &&
req.method != "DELETE") {
/* Non-RFC2616 or CONNECT which is weird. */
return (pipe);
}
if (req.method != "GET" && req.method != "HEAD") {
/* We only deal with GET and HEAD by default */
return (pass);
}
# if (req.http.Authorization ) {
# /* Not cacheable by default */
# return (pass);
# }
if (req.url ~ "test" && req.http.Cookie) {
return (hash);
}
if ( req.http.Cookie) {
return (hash);
}
return (hash);
}
sub vcl_backend_response {
# Happens after we have read the response headers from the backend.
#
# Here you clean the response headers, removing silly Set-Cookie headers
# and other mistakes your backend does.
}
sub vcl_deliver {
# Happens when we have all the pieces we need, and are about to send the
# response to the client.
#
# You can do accounting or modifying the final object here.
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
}
sub vcl_hash {
hash_data(req.url);
if (req.http.host) {
hash_data(req.http.host);
} else {
hash_data(server.ip);
}
hash_data(req.http.Cookie);
# if( req.http.Cookie ~ "testvarnish" ) {
# set req.http.X-Varnish-Hashed-On = regsub( req.http.Cookie,
"^.*?testvarnish=([^;]*);*.*$", "\1" );
# }
# if( req.http.X-Varnish-Hashed-On ) {
# hash_data( req.http.X-Varnish-Hashed-On);
# }
return (lookup);
}
sub vcl_pass {
# Called upon entering pass mode. In this mode, the request is passed on
to the backend, and the
# backend's response is passed on to the client, but is not entered into
the cache. Subsequent
# requests submitted over the same client connection are handled normally.
}
On Wed, May 13, 2015 at 5:45 PM, Raymond Gonzalez <raygo22 at gmail.com> wrote:
> I did but it only says what to put in vcl_hash
>
> > On May 13, 2015, at 5:37 PM, Thomas Lecomte <
> thomas.lecomte at virtual-expo.com> wrote:
> >
> >> On Wed, May 13, 2015 at 11:34 PM, Raymond Gonzalez <raygo22 at gmail.com>
> wrote:
> >> Hi Thomas. Thanks for that. No, I'm very new at working with varnish (1
> day old) so don't really know how to do what you are telling me. Could you
> please let me know what I should put or where can I find a tutorial to do
> this? A lot of what I've found online is not for V4 so it's not working.
> Thanks!
> >
> > Have you checked out this page?
> >
> > https://www.varnish-cache.org/trac/wiki/VCLExampleCacheCookies
> >
> > It seems to be Varnish 4-compliant.
> >
> > Hope this helps,
> >
> > --
> > Thomas Lecomte
>
--
Raymond Gonzalez
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20150513/8380bc18/attachment-0001.html>
More information about the varnish-misc
mailing list