Varnish 4 Example with Apache, WordPress, Woocommerce, Memberships, and more.

It was a long journey to get a working Varnish 4.0 to behave with WordPress and all of its dynamic plugins (such as Paid Memberships Pro PMP, Woocommerce, WordPress Social Login, etc), however the journey is not over…yet. I found myself scattered around the internet looking for resources about Varnish and the various scripts I am using. Thus I decided to write this guide and share my Varnish example. I am adding my experience here in hopes I can get feedback from you, the pros and beginners, and hopefully help some people along the way. In terms of Varnish performance and optimization, my goal is to achieve a decent hit rate on static content while leaving dynamic member content dynamic.  Cheers!

Subscribe to Psynaps YouTube Watch Psynaps Live on Twitch

About my setup

I am running 5+ wordpress sites on the same server, each with WP Super Cache. I am finding that this config, along with WP Super Cache is making my website very fast (try it www.psynapticmedia.com).

This will work well for multisite, as I am running multiple wordpress sites and each one has a different need for cookie management. For example, I want my blog to be more static and have a high hit rate, however I want my members site to be more dynamic as each member will have a unique session. Of course I want my woocommerce shop to be functional so sales can be processed. You will see the “do not cache” area and the cookie madness below that makes this possible.

A working default.vcl

(updated 06-14-15)

 

Whats missing?

– WordPress Purge needs to be implemented and tested.
– Smarter grace period.
– Others? Leave me your comments!

How to watch the magic

In the console, check your HIT and MISS.  -w 10 refreshes every 10 seconds

Realtime log for troubleshooting.

 

Helpful Resources and Examples

https://github.com/mattiasgeniar/varnish-4.0-configuration-templates
https://wordpress.org/support/topic/good-varnish-4-defaultvcl
https://gist.github.com/nadirlc/46987b42447cf8e3be79

Join the discussion 5 Comments

Leave a Reply