1

I've configured Varnish 4.0 through authcache and its working perfectly fine for anonymous users but for authenticated users it always shows "MISS" both in authcache debug and browser response headers. Drupal logs shows following message:

"Varnish: Cache-Control header with max-age=0 on response. Varnish will not store this response." But on checking response headers in browser shows "max-age=432000"

        #######
Accept-Ranges: bytes
Age: 0
Cache-Control: public, max-age=432000
Connection: keep-alive
Content-Encoding: gzip
Content-Language: en
Content-Length: 6663
Content-Type: text/html; charset=utf-8
Date: Thu, 04 Feb 2016 07:17:31 GMT
Etag: "1454570251-1-21a69a4"
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Last-Modified: Thu, 04 Feb 2016 07:17:31 GMT
Server: Apache/2.2.15 (CentOS)
Set-Cookie: SESS6621be2effc350e524c26ac1457d7607=t_EB-SqlJSlYCNxf0hxozSMSx1O-2p6Sj9K24erZMV8; path=/; domain=.forumies.co.in; HttpOnly
Vary: Accept-Encoding, Cookie
Via: 1.1 varnish-v4
X-Generator: Drupal 7 (http://drupal.org)
X-Powered-By: PHP/5.6.17
X-Varnish: 163934
X-Varnish-Cache: MISS
x-content-type-options: nosniff, nosniff
#########

Below in my default.vcl

    include "/var/www/html/sites/all/modules/authcache/modules/authcache_varnish/varnish-4/core.vcl";

sub authcache_key_path {
  set req.http.X-Authcache-Key-Path = "/authcache-varnish-get-key";
}

sub authcache_key_cid {
  if (req.http.Cookie ~ "(^|;)\s*S?SESS[a-z0-9]+=") {
       set req.http.X-Authcache-Key-CID = "sess:"+regsuball(req.http.Cookie, "^(.*;\s*)?(S?SESS[a-z0-9]+=[^;]*).*$", "\2");
  }
  else {
      set req.http.X-Authcache-Key-CID = "host:"+req.http.host;
  }
}

/**
 * Place your custom vcl_recv code here.
 */
sub authcache_recv {
     if (
      req.url ~ "^/admin$" ||
       req.url ~ "^/admin/.*$" ||
       req.url ~ "^/batch.*$" ||
       req.url ~ "^/comment/edit.*$" ||
       req.url ~ "^/cron\.php$" ||
       req.url ~ "^/file/ajax/.*" ||
       req.url ~ "^/install\.php$" ||
       req.url ~ "^/node/*/edit$" ||
       req.url ~ "^/node/*/track$" ||
       req.url ~ "^/node/add/.*$" ||
       req.url ~ "^/system/files/*.$" ||
       req.url ~ "^/system/temporary.*$" ||
       req.url ~ "^/tracker$" ||
       req.url ~ "^/update\.php$" ||
       req.url ~ "^/user$" ||
       req.url ~ "^/user/.*$" ||
       req.url ~ "^/users/.*$") {
     return (pass);
   }

   if (req.http.Cookie) {
     set req.http.Cookie = ";" + req.http.Cookie;
     set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";");
     set req.http.Cookie = regsuball(req.http.Cookie, ";(S?SESS[a-z0-9]+|aucp13n|NO_CACHE|nocache|has_js|aucdbg|cache_render)=", "; \1=");
     set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", "");
     set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", "");

     if (req.http.Cookie == "") {
       unset req.http.Cookie;
     }
   }
   if (!req.http.X-Authcache-Get-Key) {
     set req.http.X-Authcache-Get-Key = "get";
   }
}

sub vcl_backend_fetch {
  }

sub vcl_backend_response {
  if (beresp.http.Cache-Control ~ "(private|no-cache|no-store)") {
     set beresp.ttl = 0s;
   }
}

sub vcl_deliver {
     if (resp.http.X-Generator ~ "Drupal" && req.http.user-agent ~ "Safari" && req.http.user-agent !~ "Chrome") {
     set resp.http.Cache-Control = "no-cache, must-revalidate, post-check=0, pre-check=0";
   }
 if (obj.hits > 0) {
     set resp.http.X-Varnish-Cache = "HIT";
   }
   else {
     set resp.http.X-Varnish-Cache = "MISS";
   }
}
  • This particular response is not cacheable because of the Set-Cookie response header. Do you have this problem also for other responses? – znerol Feb 4 '16 at 17:31
  • Same problem for all urls in case of authenticated user only. Thank for pointing out. This "Set-Cookie" header is missing in case of anonymous user. – Himanshu Sharma Feb 5 '16 at 5:56
  • Do you see the Set-Cookie header on every authenticated response from the backend? – znerol Feb 7 '16 at 14:38
  • Yes that was issue in simple-facebook-connect plugin. I've used php code in index.php to unset response "Set-Cookie" header in case the cookie to be set is already present in request "Cookie" header – Himanshu Sharma Feb 8 '16 at 17:15
  • After fixing simple-facebook-connect plugin, do you still have problems with the VCL or is this issue solved? If it is solved, then please write a short answer pointing out the real issue and accept it yourself. – znerol Feb 8 '16 at 19:53

Your Answer

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

Browse other questions tagged or ask your own question.