The following is the GNU All-permissive License as recommended in

Copyright (C) 2024 Free Software Foundation

Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. This file is offered as-is, without any warranty.

Contributions are welcome. See


This can be used with drupal8 with its tag based tracking of pages that will need an update when data changes in the site. Cache invalidation works great with this system.

clearing out the cache

systemctl restart varnish

You can also clear out a specific page or tag:

curl -q -X BAN -H "Cache-Tags: node:1"

Installing Varnish for Drupal

configuring varnish on Drupal

Use this module. Instructions are linked from the site, but the custom config we used on are described a bit below.

Varnish ignores the "Browser and proxy cache maximum age" under /admin/config/development/performance, so it only affects browsers. (I'm pretty sure that it's not used for invalidating Drupal's internal cache, but it might be worth verifying that.) 15 minutes is a good setting, and can be adjusted. Note that Drupal will display a warning about this on the Drupal dashboard, possibly because it thinks that Varnish caches will not persist for long, but that would be wrong.

varinish config

A Varnish config is required. See /etc/varnish/default.vcl for an example on

configuring apache

A useful way to set it up is to have Apache handle HTTPS on the frontend, Varnish in the middle, and Apache on the backend, which talks to PHP-FPM. See the Apache configs in for an example.

You may want to set retry=0 on the ProxyPass directive so Apache will not break when someone loads a page while Varnish is being restarted or runs into an issue.

configuring jemalloc

the malloc (memory based) backend uses jemalloc. To reduce fragmentation, run this command, then restart varnish:

ln -s "lg_dirty_mult:8,lg_chunk:18" /etc/malloc.conf