Accelerate your Drupal/Pressflow site using Varnish

Pressflow and Drupal 7 allow you to use an HTTP accelerator such as Varnish
Apache Configuration
Adjust your Apache configuration to server the Drupal site on port 8080. Edit your Apache conf file and add:

Listen 8080
NameVirtualHost *:8080

Restart Apache and make sure you can access your site on that port.

Varnish Configuration
Rather than change the default Varnish conf file, we'll create one just for Drupal:/usr/local/etc/varnish/drupal.vcl with Fourkitchens' basic configuration for Varnish 3.x and Drupal 7.

Drupal 7.x configuration
Edit your site's settings.php file and add some proxy settings:

$conf['reverse_proxy'] = TRUE;
$conf['reverse_proxy_addresses'] = array('');
$conf['reverse_proxy_header'] = 'HTTP_X_FORWARDED_FOR';
#$conf['omit_vary_cookie'] = true;

$conf['page_cache_invoke_hooks'] = false;
$conf['cache'] = 1;
$conf['cache_lifetime'] = 0;
$conf['page_cache_maximum_age'] = 21600;

Enable Drupal's page cache in admin/config/development/performance and set the Caching Mode to External and Page Cache Maximum Age to an appropriate value (anything over 0).

Varnish Module
Add to your settings.php file:

// Add Varnish as the page cache handler.
$conf['cache_backends'] = array('sites/all/modules/varnish/');
$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;

Testing Varnish
You can test that Varnish is serving a cached page or not with:

curl -I


Recent Updates

  • 9 months 2 weeks ago
  • 9 months 2 weeks ago
  • 9 months 2 weeks ago
    php 8.x
  • 9 months 2 weeks ago
  • 9 months 2 weeks ago
    Drop Centos 5/6 stuff