Information for: DEVELOPERS   PARTNERS

Using Varnish

Varnish® cache is a caching reverse proxy installed in front of all Acquia Cloud load balancing servers. Varnish increases application performance by caching anonymous user connections and serving them from memory instead of making requests to the Apache web server.

Serving pages from memory is much faster than serving them from the Drupal/Apache/MySQL/PHP stack, and also frees up resources on the server and database to handle the dynamic requests Varnish cannot handle. If Varnish can’t fulfill a page request, Varnish passes the request through to the Drupal/Apache/MySQL/PHP stack. If the response from Apache is cacheable, Varnish stores the response for faster responses to future requests.

Varnish logs are not available for log streaming in the Acquia Cloud interface, but subscriptions with dedicated load balancers can forward Varnish logs to an external service.

For more information about using Varnish, see Introduction to Varnish.

What Varnish caches

Varnish caches responses to anonymous user requests. It also caches static assets, such as images, JavaScript, and CSS, both for anonymous and authenticated user requests, assuming the assets are not stored in the Drupal private file system. Certain file types will always be excluded from Varnish caching, and you can alter the caching behavior of other file types by creating a custom caching policy per file type.

Files larger than 10 MB are not cached

On Acquia Cloud, Varnish can cache files smaller than 10 MB in size, but never caches any object greater than 10 MB in size. Learn more.

To determine how Varnish caching is working with your application, you can examine the Varnish caching headers sent with each page and asset request. For more information, see Varnish headers.

Configuring Varnish

You cannot configure Varnish yourself. Acquia has configured the shared Varnish installation in a way we believe is optimal for most applications. If you are an Acquia Cloud Enterprise customer, and you have dedicated load balancers, custom Varnish configurations may be available through an Acquia Professional Services engagement. See Custom Varnish configuration for Acquia Cloud Enterprise applications Acquia Cloud Enterprise and contact your Acquia account manager for more information.

Do not install the Varnish Drupal module on applications hosted on Acquia Cloud. The module requires connections to the load balancers which Acquia does not provide, and the module will not work properly.

Configuring Drupal cache settings for Varnish

You must configure your Drupal application to take advantage of Varnish. To set your website’s cache options to external caching, open your Drupal application’s Performance page. The cache settings depend on your version of Drupal:

Note for Acquia Cloud Site Factory users

Changing Acquia Cloud Site Factory caching settings requires you to create a post-settings.php hook.

  • Drupal 8 cache settings

    On the Performance page at /admin/config/development/performance, select an option from the Page cache maximum age list. This value sets the maximum time a page can stay in the Varnish cache. Selecting <no caching> sets the max-age value to 0, which means assets are never cached. A reasonable value is 6 hours to 12 hours.

    Drupal 8 cache settings

    To configure Drupal 8 to use BigPipe rendering, see Enabling BigPipe rendering on Acquia Cloud.

  • Drupal 7 cache settings

    On the Performance page at Configuration > Performance, set values for the following items:

    Drupal 7 cache settings

    • Cache pages for anonymous users check box – Select this check box.
    • Minimum cache lifetime list – Use this setting with caution. The minimum cache lifetime prevents Drupal from clearing page and block caches for a set period of time after you change the content of nodes or blocks. This setting can cause unexpected behavior when editing content or when using an external cache such as Varnish. If you are unsure, leave the minimum cache lifetime set to 0.
    • Expiration of cached pages list – This value is the maximum time a page can stay in the Varnish cache. By setting this value to <none>, the max-age header Drupal sends to Varnish is 0, which means the page will not be cached. A reasonable expiration setting is from 6 hours to 12 hours.


    For Drupal 7 and earlier versions, Acquia strongly recommends you do not compress cached pages, as compression can cause problems with both Varnish caching and New Relic application monitoring.

Bypassing the Varnish cache

Sometimes you may have a few pages with random or dynamic content you do not want cached. You can selectively exclude certain paths from caching so dynamic content is actually dynamic. For information about how to do this, see Bypassing the Varnish cache.

Varnish over SSL

Acquia provides Varnish for use with connections secured by SSL. To enable Varnish caching for your SSL-enabled website, complete the following steps:

  1. Sign in to Acquia Cloud, and then select your application and environment.
  2. On the Overview page for the environment, click the Configure gear icon.
  3. In the Varnish section, select the Varnish through SSL check box.
  4. Click Save.

The activity icon will display that the change is in progress. After the process completes, Varnish over SSL is enabled for the website.

Clearing the Varnish cache

You can clear (flush or purge) the Varnish cache using the Acquia Cloud interface:

  1. Sign in to Acquia Cloud, and then select your application and environment.
  2. On the Overview page for the environment, click Clear Varnish.
  3. In the Clear caches dialog box, select the domains for which you want to clear the Varnish caches. You can click All to clear the Varnish caches for all domains in this environment. Then click Clear to confirm. All check boxes are selected by default, and your selections are maintained.

You can also purge individual pages from Varnish cache with the Acquia Purge module user interface, or with command-line commands. For more information, see Purging Varnish cache on Acquia Cloud.

Varnish is a registered trademark of Varnish Software AB and its affiliates.