Purchase a pre-installed image of WordPress optimized with Varnish and W3 Total Cache as described in this tutorial (hosted at Digital Ocean). This is the simplest and fastest way to get started with a self-hosted, pre-optimized version of WordPress. It’s also a great way to experiment with this tutorial. Buy now for $10 | Learn more
Depending on the complexity of your WordPress theme, performance can actually be quite slow on AWS. That’s where Varnish can make a tremendous difference. Varnish is a cache which stores copies of pages for users that aren’t logged in (most aren’t). When requests come in to your server, Varnish returns these pre-built pages instantly rather than requiring Apache, PHP and WordPress to rebuild the page for each request. Later, W3 Total Cache can be set up to regularly pre-build pages of your site so they are always ready for Varnish. The power of Varnish is dramatic when interest in your site spikes such as an appearance on BoingBoing, Slashdot or Oprah or @itsthegrumpycat.
We’ll set up Varnish to listen for HTTP (web) traffic on port 80 with Apache listening only to Varnish on port 8080. When Varnish needs a page to be built manually, it will pass the request on to Apache port 8080.
To get started, we need to install Varnish on our instance:
sudo apt-get install varnish
Edit Apache’s ports.conf file to listen on port 8080:
sudo nano /etc/apache2/ports.conf
Here’s what it should look like:
NameVirtualHost *:8080 Listen 8080
Edit your Apache site configuration file to respond to port 8080:
sudo nano /etc/apache2/sites-available/wordpress
Change the VirtualHost line from *:80 to *:8080
You may need to change your Apache default site to listen on port 8080 or disable it:
sudo a2dissite 000-default
Move the original Varnish configuration files to your home directory as backups (in case you decide to review them later):
sudo mv /etc/default/varnish ~/default-varnish-old sudo mv /etc/varnish/default.vcl ~/varnish-default-vcl.old
Replace the Varnish default configuration with the file below (copy and paste).
sudo nano /etc/default/varnish