Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

How to configure Varnish

Carl Alexander edited this page Oct 5, 2016 · 2 revisions

Contents

  1. Plugins
  1. Updating your Varnish configuration

How to configure Varnish

Varnish is a powerful component of the modern WordPress server stack. It serves as the HTTP caching layer and allows your WordPress installation to handle a lot of traffic. This guide will show you how to configure Varnish beyond the default DebOps configuration.

This guide assumes that you're familiar with how to customize your server. If you don't know how or aren't sure, take a moment to go over this guide first.

Plugins

By default, DebOps only configures Varnish to work with the default WordPress installation. This means that Varnish might have issues with certain plugins. Below are plugins that need some extra Varnish configuration to work without issues.

Varnish HTTP Purge

Varnish HTTP purge is a plugin created by Dreamhost for its infrastructure. That means that there's no guarantee that it'll work with DebOps. The good news is that it pretty much works out of the box! The configuration below is only necessary if you want the "Purge Varnish" button to work.

wordpress__varnish__add_ban_lurker_headers: True
wordpress__varnish__purge_conditions:
  'req.http.X-Purge-Method ~ "(?i)regex"': |
    ban("obj.http.X-Url ~ " + req.url + " && obj.http.X-Host == " + req.http.host);
    return (synth(200, "Purged"));

WooCommerce

As an eCommerce platform, WooCommerce requires that a lot of its pages stay uncached. This is because a lot of visitors won't log in, but will still need pages rendered by WordPress. The configuration below implements the recommendations from the WooCommerce documentation.

wordpress__varnish__vcl_recv_conditions:
  'req.url ~ "^/(cart|my-account|checkout|addons)" || req.url ~ "\?add-to-cart="': 'return (pass);'

Updating your Varnish configuration

You don't need to create a new server to make changes to Varnish. DebOps can update an existing server with the configuration changes that you've made. You just need to run the WordPress DebOps playbook with the `depend::varnish`` tag.

$ debops wordpress --tags depend::varnish