Implementing Varnish on Magento 1

Is Varnish right for you?

Varnish isn’t the be-all and end-all of Magento performance. Its great to offset load from bots & window-shoppers – but it shouldn’t be your first port of call to actually making your store faster.

Implementing Varnish should be the last performance modification to your store. Only drop it in once you are seeing the page load times Magento is capable of delivering without it (Eg. <600ms page load times).

Read more about the suitability of Varnish.

Implementation

There are 4 crucial steps to implement Varnish,

  1. Identify all admin/frontend routes/namespaces that should never be cached
  2. Define Nginx excludes for the routes identified
  3. Install a supporting store-side Varnish module (Eg. MageStack_Varnish (see "Automated installer" below) or Ecomdev_Varnish)
  4. Testing and verification

Varnish is already installed and pre-configured server-side, so no actual application installation is required, you merely need to add the supporting elements to your store itself.

Automated installer

MageStack has an automated installer to identify admin and frontend routes, define them, install a store-side module and then create the suitable configuration file to use.

You can execute it simply by changing to your Magento document root and running the script,

Eg. For example.com

cd /microcloud/domains/example/domains/example.com/http
/microcloud/scripts_ro/varnish_install.sh

After installation, you'll be prompted with a success message,

Success: Configuration complete. Add the following to the top of ___general/example.com.conf to enable Varnish
include /microcloud/data/domains/example/domains/example.com/___general/varnish.include.conf;

Then edit ___general/example.com.conf as instructed, adding the new configuration file and then reloading Nginx.

The final step is to enable Varnish in your Magento admin in System > Cache Management.

The default rules produced in ___general/varnish.include.conf are considered "safe" - but by no means final. They can (and should be) refined to suit the needs of your cacheable content. Making them less restrictive will improve cacheability.

! Considerable testing should first be performed in a development environment before live implementation.