Skip to main content
How to Use Varnish at Cloudways

This KB article explains how you can install and configure Varnish as part of your optimization stack on the Cloudways Platform.

Emmad avatar
Written by Emmad
Updated over a week ago

Table of Contents

The Cloudways Platform offers a robust server-level caching solution as a part of our optimization stack known as Varnish.

What is Varnish?

Varnish Cache (often called “Varnish”) is an open-source HTTP web accelerator designed to cache and deliver static and dynamic content requests for dynamic websites. It enables websites to load faster and helps reduce the server's load to endure a high volume of traffic.

Cloudways servers are shipped with Varnish pre-installed, so you and your website visitors enjoy faster load times and a premium user experience. The current version of Varnish is 6.0.x.

Benefits of Using Varnish

Varnish is very useful for those websites dealing with heavy traffic as such websites become slow over time, and the increased waiting time destroys the user experience.

Varnish is positioned in the middle of the browser (client) and the web server. When a client requests information from the server, Varnish saves a copy of all the requested information. When the same resource is requested next time, the request is served by Varnish; thus, it boosts the website's speed by saving the time and resources it takes for a server to fulfill that request. This boost helps to enhance the user experience of the website, helps in customer retention, and increases the chances of a high search position, as Google considers it a ranking factor.

In addition, Varnish learns about the resources that are being accessed frequently and gradually caches more data to serve the requests quickly. As a result, your server does not encounter much load, and your websites continue to perform well by serving requests from the Varnish cache.

If your web server goes down or encounters any failure, Varnish will still deliver the cached pages of your website.

Varnish Compatibility with Web Applications

Varnish is fully compatible with the following web applications:

  1. WordPress (including WooCommerce and WordPress Multisite)

  2. Magento 2

Varnish is not compatible with the following web applications:

  1. Laravel

  2. Custom PHP

Default Configurations of Varnish

Cloudways Varnish Cache is an intelligent caching solution. By default, it has all the necessary configurations pre-applied, including which pages and cookies to cache and which to avoid for WordPress and Magento applications. Such configurations ensure that only the pages and cookies you need are cached and served by Varnish. These configurations are stored in the VCL file, which is the Varnish configuration file. It is also highly customizable and flexible; therefore, you can exclude cookies and pages of your own choice from the Cloudways Platform.


Here is a list of all the essential items, cookies, and URLs excluded by default for WordPress and Magento applications.

Item Name

Description

POST

All POST requests are excluded.

HTTP Authorization

All password-protected websites are excluded.

WordPress Specific Configurations

The following are the WordPress-specific configurations that Varnish excludes by default.

Item Name

Description

WordPress Pages

All of the following WordPress pages are excluded.

  • /wp-login.php

  • /wp-admin

  • /wp-json

  • /wp-cron

  • /membership-account

  • /membership-checkout

  • /wp-comments-post.php

  • /?preview=true

  • /xmlrpc.php

WooCommerce Pages

All of the following WooCommerce specific pages are excluded.

  • /cart

  • /my-account

  • /checkout

  • /wc-api

  • /addons

  • /?add-to-cart=

  • /add-to-cart

  • /logout

  • /lost-password

  • /administrator

  • /?wc-ajax=get_refreshed_fragments

Cookies

All of the following cookies are excluded.

  • wordpress_logged_in

  • resetpass

  • wp-postpass

  • wordpress_

  • comment_

  • woocommerce_cart

  • woocommerce_session

  • wp_woocommerce_session

RSS Feed

/feed are excluded.

Easy Digital Downloads Pages and Cookies

All of the following pages and cookies are excluded.

  • edd_action

  • ^edd

  • ;\s*edd

Magento Specific Configurations

Magento 2 supports Varnish out-of-the-box; therefore, you don't require any third-party extensions. Cloudways also use the default VCL file with default settings, which Magento 2 offers.

How to Manage Varnish

By default, Varnish is enabled on all the Cloudways servers. When you enable Varnish on the server, the Varnish caching is enabled on all the applications hosted on that server. When you disable Varnish on the server, the Varnish caching is disabled on all the applications hosted on that server. There is also an option to enable Varnish on the server but disable the service on a particular application.

Enable/Disable Varnish on the Server

Here is how you can enable or disable Varnish on the server using the Cloudways Platform.

Log in to your Cloudways Platform using your credentials.

  1. From the top menu bar, open Servers.

  2. Next, choose your desired server.

    Classic Interface

    New Interface

  3. Under Server Management, select Manage Services.

  4. Next, click Enable in front of Varnish to activate the service. Likewise, you can disable Varnish by clicking Disable.

    Classic Interface

    New Interface

Disable Varnish on Specific Application

You can disable Varnish on a specific application but keep the Varnish active on the server.

Important

Before proceeding further, ensure that the Varnish caching is enabled on the server.

  1. From the top menu bar, open Servers.

  2. Then, choose the server where your desired application is deployed.

    Classic Interface

    New Interface

  3. Next, click www.

  4. Choose your application.

    Classic Interface

    New Interface

  5. Under Application Management, navigate to Application Settings.

  6. Currently, the Varnish is enabled; therefore, click Disable Varnish.

    Classic Interface

    New Interface

  7. Finally, click OK to save the changes. It will disable the Varnish for that specific application.

    Classic Interface

    New Interface

How to Exclude URLs and Cookies in Varnish

The default configurations of Varnish are sufficient, but you can also exclude several URLs and cookies in Varnish caching based on your requirements.

Important

Before proceeding further, ensure that the Varnish caching is enabled on the server.

  1. From the top menu bar, open Servers.

  2. Then, choose the server where your desired application is deployed.

    Classic Interface

    New Interface

  3. Next, click www.

  4. Choose your application.

    Classic Interface

    New Interface

  5. Under Application Management, navigate to Application Settings.

  6. Switch to the Varnish Settings tab.

  7. Click Add New Exclusion.

    Classic Interface

    New Interface

URL Exclusion

  1. To exclude a URL, Select URL as Type.

  2. Type the Value, such as the URL you want to exclude from Varnish caching.

  3. Finally, click Save.

Important

  • Only relative URLs can be excluded from caching (e.g., /mypage.php) and not absolute URLs (http://mywebsite.com/mypage.php). Regular expressions can also be used.

  • Excluding URL (path) prevents Varnish from caching that specific resource. For instance, if you exclude a URL (/mypage.php), that file will not be cached by Varnish.

  • If you use an incomplete destination URL such as (/booking/) and if such path has more succeeding links such as booking/list or booking/items, all such items will not be cached by Varnish.

Classic Interface

New Interface

Cookies Exclusion

  1. To exclude a cookie, Select Cookie as Type.

  2. Type the Value such as the cookie name you want to exclude from Varnish caching.

  3. Finally, click Save.

Important

  • The cookie value will be the full cookie name. Regular expressions can also be used.

  • Excluding specific cookies would prevent the cookie strings caching and would allow them to work, bypassing caches. This is used when cookies create different sessions and calls are unique. These cookie sessions are regularly updated and therefore are excluded from caching so that the sessions can be appropriately updated.

Classic Interface

New Interface

Once you have added all the rules, they will be visible in the same section. These rules can be easily edited or removed whenever needed. You may need to use Varnish Purge if objects/URLs are previously being cached.

Classic Interface

New Interface

How to Change Varnish TTL

The Cloudways Platform offers a robust server-level caching solution known as Varnish. Our servers come with Varnish pre-installed, so you and your website visitors enjoy faster load times for the premium experience.

This section describes how to change the Varnish Time-to-Live (TTL) using the Cloudways Platform. Varnish is the secret ingredient behind our trailblazing stack to improve your website’s performance. The time period for which Varnish caches content before being refreshed is called cache lifetime or Time-To-Live (TTL). The default TTL value is set to 4 hours. Setting an optimum time helps to achieve significantly faster load times, which gives you an SEO boost and reduces the server's load.

Important

Changing the TTL is a server-level configuration; thus, all websites (or applications) hosted on the same server, including staging sites, will be affected.

Here is how you can view and change the TTL value for Varnish in just a few clicks using the Cloudways Platform.

  1. From the top menu bar, open Servers.

  2. Next, choose your desired server.

    Classic Interface

    New Interface

  3. Under Server Management, select Settings and Packages.

  4. Next, switch to the Advanced tab.

    Classic Interface

    New Interface

Once you scroll down, you will see the Cache Lifetime option under Varnish.

  1. Choose the value for the cache lifetime. For example, you can select 4 hours, 8 hours, 14 hours, or 24 hours.

  2. Finally, click Save Changes.

    Tip

    If you make frequent changes to your website, we encourage you to set a lower value for the TTL. On the other hand, increasing your TTL value is recommended if you do not make frequent content changes.

    Classic Interface

    New Interface

That’s it! We hope this tutorial was helpful. If you need any help, then feel free to search your query on Cloudways Support Center or contact us via chat (Need a Hand > Send us a Message). Alternatively, you can also create a support ticket.

FAQs

What is Varnish?

Varnish Cache (often called “Varnish”) is an open-source HTTP web accelerator designed to cache and deliver static and dynamic content requests for dynamic websites. It enables websites to load faster and helps reduce the server's load to endure high traffic.

Does Varnish Cache Support HTTPS?

Applications, plugins, and extensions that support Varnish on Cloudways Platform will also work with HTTPS.

Does Varnish Cache 404 Pages?

Yes, Varnish Cache can indeed cache 404 pages with a default Time-To-Live (TTL) duration of 5 minutes.

Did this answer your question?