Varnish

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('127.0.0.1');
$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/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;

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

curl -I http://yoururl.com

Resources

Recent Updates

  • 8 months 3 weeks ago
    1.27.2 update
  • 9 months 3 days ago
    Drupal 10/11 config
  • 9 months 5 days ago
  • PHP
    9 months 5 days ago
    PHP 8.3.11 and AlmaLinux
  • 9 months 5 days ago
    New version of Pound