In this KB:
- What do Varnish Rules do
- How to Exclude (bypass) URLs from Varnish
Varnish can improve website performance through caching dynamic content. Generally, e-commerce websites with secure cart pages are not set up for being cached. Through this feature, specific pages can be excluded whenever required.
Click here to find out how to exclude/include cookies in Varnish.
Step 1: Select the Target Application
Log into the Cloudways Platform with your credentials. Click on Applications in the top menu bar and select the target application from the list.
Step 2: Check if Varnish is Enabled
From the Application Settings section in the Application Management area, enable Varnish. If it is disabled from this section, Varnish settings would not be available for use.
Step 3: Add Varnish Rule
Before proceeding with add the Varnish rules, it is really important that you refer to the following notes:
- Excluding from Varnish excludes the entire link from Varnish to prevent caching on it. If you exclude a link (/file.php) then that file would not cache through Varnish.
- If you use an incomplete destination link (/checkout/) and can have several links after checkout/ such as checkout/cart or checkout/items, all links with checkout/ would not cache through Varnish.
Now Select Varnish Settings. Then, click Add New Rule.
Choose URL from the Type drop-down menu that you wish to exclude. Enter your string in the Value input field. In this example, all links using /checkout/ will be excluded from Varnish and would not cache content.
Note: Only relative URLs can be excluded from caching (eg: /checkout/) and not absolute URLs (http://domain.com/checkout/).
Tip: Regex can also be used.
Once added, the rule will be visible in the Varnish Settings section. The rule can be edited or removed whenever needed.
- You may need to use Varnish Purge if objects/URLs are previously being cached.