In this KB
- What do Varnish Rules do
- How to Include (allow Varnish to Cache) Cookies
- How to Exclude (bypass from Varnish) Cookies
- Important Notes
Varnish is a cache service used to cache dynamic content on websites to improve their performance. Some websites such as e-commerce stores with secure cart pages or sessions do not require caching. This feature allows specific cookies to be excluded or included as per your requirements.
Click here to find out how to exclude URLs from Varnish.
Step 1: Select the Target Application
Log into the Cloudways Platform with your credentials. Click on Applications in the top menu bar and then select your target application from the list.
Step 2: Check if Varnish is Working
Go to the Application Settings section under the Application Management area. Make sure that Varnish is Enabled. If it is disabled from this section, then the Varnish settings would not be available.
Step 3: Add Varnish Rule
Before proceeding with adding the rules, it is really important that you refer to the following notes:
- Including Cookies such as $cookie_name (user_243545) would include it in our Varnish VCL and would cache its data. Cookies that are generally included are those that have the same variables, calls, sessions being represented for each client. These do not need to be regularly updated and therefore can be included in varnish cache.
- Excluding cookie such as $cookie_name (user_2545) would prevent the cookie strings caching and would allow them to work bypassing caches. This is used when cookies create different sessions and calls and are unique. These cookie sessions are regularly updated and therefore are excluded from caching so that the sessions can be properly updated.Now click on Varnish Settings and then click on Add New Rule.
Choose the Type (Cookie), Method (Include or Exclude) and add the Value. Then click on Save to finalize the rule.
Tip: The cookie value can be the full cookie or the name. Regex can also be used.
Once the rule is added it would be visible in the Varnish Settings tab. The rule can be edited or removed whenever required.
- You may need to use Varnish Purge if objects/URLs are previously being cached.