Varnish Cache for Drupal 7 on Ubuntu Systems

These are my notes for install varnish proxy cache on ubuntu systems for Drupal:

Here are my notes for config and Pressflow, (Drupal 6), Drupal 7 and Drupal 8 experiences....

Drupal 6

Drupal 6 = PRESSFLOW => https://launchpad.net/pressflow + http://pressflow.org/

- http://www.modernfidelity.co.uk/varnish-install-on-ubuntu-9.x-notes

Drupal 7

Here is the official page on varnish-cache.org => https://www.varnish-cache.org/trac/wiki/VarnishAndDrupal

And here is the starting config for varnish:

sub vcl_recv {
  // Remove has_js and Google Analytics __* cookies.
  set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(__[a-z]+|has_js)=[^;]*", "");
  // Remove a ";" prefix, if present.
  set req.http.Cookie = regsub(req.http.Cookie, "^;\s*", "");
  // Remove empty cookies.
  if (req.http.Cookie ~ "^\s*$") {
    unset req.http.Cookie;
  }

  // Cache all requests by default, overriding the
  // standard Varnish behavior.
  // if (req.request == "GET" || req.request == "HEAD") {
  //   return (lookup);
  // }
}

sub vcl_hash {
  if (req.http.Cookie) {
    set req.hash += req.http.Cookie;
  }
}

The varnish drupal module can also be found here => http://drupal.org/project/varnish

D7 version uses a cache backend plugin that can be used for cache_page instead of the built in database cache. In order to get the Varnish module working for D7, you need to include an amend to the 'settings.php' :

<?php
// Add Varnish as the page cache handler.
$conf['cache_backends'] = array('sites/all/modules/varnish/varnish.cache.inc');
$conf['cache_class_cache_page'] = 'VarnishCache';
// Drupal 7 does not cache pages when we invoke hooks during bootstrap. This needs
// to be disabled.
$conf['page_cache_invoke_hooks'] = FALSE;
?>

Really Useful Links :
http://blogs.osuosl.org/gchaix/2009/10/12/pressflow-varnish-and-caching/
http://groups.drupal.org/pantheon/documentation
http://drupal.org/node/1196916




I would love to see this! I'm in the process of tinkering on my site GeekGirlDev.com to get the latest version of Varnish up and playing nicely with Drupal 7.

-Becca

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. The supported tag styles are: <foo>, [foo].

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.
Bg