2

I am trying figure out how to allow the backend to see tracking cookies on specific registration pages but ignore them on others. Currently, I'm trying to use a custom header sent from the backend to set beresp.ttl = 0s; inside the vcl_fetch:

if (beresp.http.cache-control ~ "max-age=-30") { set beresp.ttl = 0s; }

But the reg pages still prevent the backend from reading the cookie.

In the vcl_recv I am removing them by using this method:

set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(__[a-z]+|_ga|_mkto_trk)=[^;]*", "");

set req.http.Cookie = regsub(req.http.Cookie, "^;\s*", "");

if (req.http.Cookie ~ "^\s*$") { unset req.http.Cookie; }

How can I allow the cookie to get read on the backend on these specific pages? I assume I need to create exceptions in the vcl_recv?

1
  • I don't know how to allow specific cookies, but +1 for the example of how to remove the new Google Analytics cookie amongst others, found suprisingly few examples of this other than ones for __utm*.
    – Steve
    Mar 11, 2014 at 21:39

1 Answer 1

0

Yes - you need to "return( miss );" on the requests in the backend. vcl_fetch is only triggered on 'fetching' an item from the backend - if an item is already stored in cache, varnish will not run the fetch code.

3
  • So I should return(miss); in beresp conditional instead of or along with the ttl = 0s?
    – Taylor
    Mar 17, 2014 at 17:12
  • I tried this but it still doesn't allow my tracking cookies to pass to the backend even though it has told varnish to miss the cache. My backend needs to be able to see some of these cookies for each user.
    – Taylor
    Mar 17, 2014 at 23:47
  • return(hit_for_pass), sorry, I thought you were operating in vcl_recv. You can read more about what hit_for_pass is doing here: stackoverflow.com/questions/12691489/varnish-hit-for-pass-means
    – Kirrus
    Mar 18, 2014 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.