<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
When I use the code below (based on the templates at
<a class="moz-txt-link-freetext" href="https://github.com/mattiasgeniar/varnish-3.0-configuration-templates/tree/master/conf.d">https://github.com/mattiasgeniar/varnish-3.0-configuration-templates/tree/master/conf.d</a>),
Drupal 7 + Varnish 3 'almost' works.<br>
<br>
Varnish is working perfectly (no backend calls, two Varnish timestamps
in the header). <br>
However, I can't log in in my Drupal site. Same behaviour with
directories which are protected by .htaccess. The logon screen keeps
popping up when I enter the correct credentials.<br>
<br>
My default.vcl:<br>
<br>
/TEMPLATE/<br>
<br>
backend default {<br>
  .host = "127.0.0.1";<br>
  .port = "80";<br>
  .connect_timeout = 600s;<br>
  .first_byte_timeout = 600s;<br>
  .between_bytes_timeout = 600s;<br>
}<br>
<br>
sub vcl_recv {<br>
<br>
# A configuration file specific for Drupal 7<br>
<br>
# Either the admin pages or the login<br>
if (req.url ~ "/admin/?") {<br>
        # Don't cache, pass to backend<br>
        return (pass);<br>
}<br>
<br>
# Remove the "has_js" cookie<br>
set req.http.Cookie = regsuball(req.http.Cookie, "has_js=[^;]+(; )?",
"");<br>
<br>
# Remove the "Drupal.toolbar.collapsed" cookie<br>
set req.http.Cookie = regsuball(req.http.Cookie,
"Drupal.toolbar.collapsed=[^;]+(; )?", "");<br>
<br>
# Remove any Google Analytics based cookies<br>
set req.http.Cookie = regsuball(req.http.Cookie, "__utm.=[^;]+(; )?",
"");<br>
<br>
# Remove the Quant Capital cookies (added by some plugin, all __qca)<br>
set req.http.Cookie = regsuball(req.http.Cookie, "__qc.=[^;]+(; )?",
"");<br>
<br>
# Are there cookies left with only spaces or that are empty?<br>
if (req.http.cookie ~ "^ *$") {<br>
        unset req.http.cookie;<br>
}<br>
<br>
# Static content unique to the theme can be cached (so no user uploaded
images)<br>
if (req.url ~ "^/themes/" && req.url ~
"\.(css|js|png|gif|jp(e)?g)") {<br>
        unset req.http.cookie;<br>
}<br>
<br>
# Normalize Accept-Encoding header (straight from the manual:
<a class="moz-txt-link-freetext" href="https://www.varnish-cache.org/docs/3.0/tutorial/vary.html">https://www.varnish-cache.org/docs/3.0/tutorial/vary.html</a>)<br>
if (req.http.Accept-Encoding) {<br>
        if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$") {<br>
                # No point in compressing these<br>
                remove req.http.Accept-Encoding;<br>
        } elsif (req.http.Accept-Encoding ~ "gzip") {<br>
                set req.http.Accept-Encoding = "gzip";<br>
        } elsif (req.http.Accept-Encoding ~ "deflate") {<br>
                set req.http.Accept-Encoding = "deflate";<br>
        } else {<br>
                # unkown algorithm<br>
                remove req.http.Accept-Encoding;<br>
        }<br>
}<br>
<br>
# Don't cache the install, update or cron files in Drupal<br>
if (req.url ~ "install\.php|update\.php|cron\.php") {<br>
    return (pass);<br>
}<br>
<br>
# Uncomment this to trigger the vcl_error() subroutine, which will HTML
output you some variables (HTTP 700 = pretty debug)<br>
#error 700;<br>
<br>
# Anything else left?<br>
if (!req.http.cookie) {<br>
        unset req.http.cookie;<br>
}<br>
<br>
# Try a cache-lookup<br>
return (lookup);<br>
<br>
}<br>
<br>
<br>
sub vcl_fetch {<br>
<br>
# For static content related to the theme, strip all backend cookies<br>
if (req.url ~ "^/themes/" && req.url ~
"\.(css|js|png|gif|jp(e?)g)") {<br>
    unset beresp.http.cookie;<br>
}<br>
<br>
# A TTL of 30 minutes<br>
    set beresp.ttl = 1800s;<br>
}<br>
<br>
<br>
<br>
/TEMPLATE/<br>
<br>
<br>
Regards.<br>
<br>
<br>
<br>
Mattias Geniar wrote:
<blockquote
 cite="mid:18834F5BEC10824891FB8B22AC821A5A01735124@nucleus-srv01.Nucleus.local"
 type="cite">
  <blockquote type="cite">
    <pre wrap="">Sadly, no...

I tried several  configurations but still without success.
(The only 2 cookies with D7 are has_js and Drupal.toolbar.collapsed.)
    </pre>
  </blockquote>
  <pre wrap=""><!---->
Perhaps you can have a look at these Drupal templates (_drupal_7-fetch/receive): <a class="moz-txt-link-freetext" href="https://github.com/mattiasgeniar/varnish-3.0-configuration-templates/tree/master/conf.d">https://github.com/mattiasgeniar/varnish-3.0-configuration-templates/tree/master/conf.d</a>
Or the one linked at drupal.org: <a class="moz-txt-link-freetext" href="http://drupal.org/files/issues/default.vcl_.txt">http://drupal.org/files/issues/default.vcl_.txt</a>

These seem to yield great results for me, with a default Drupal 7 nearly all pages can be cached.

Regards,
Mattias Geniar


  </pre>
</blockquote>
</body>
</html>