---
title: "Varnish VCL"
url: https://docs.corefinity.com/guides/sites/software-and-services/custom-vcl
type: guide
last_updated: 2026-11-13
feature: varnish-vcl
---
# Varnish VCL

Add your own VCL snippets to a Magento 2 site's Varnish, test them and go back to an earlier revision.

## Before you start

- You can open the site in **Managed Websites**. Anyone who can open a site can change its VCL.
- [Varnish](/guides/sites/software-and-services/varnish) is on. The **Varnish VCL** section shows only while it is.

## Add a snippet

1. **Open Varnish VCL**

   Go to **Managed Websites**, choose the site, then **Varnish VCL** under **Site settings**.

   _Screenshot: A Magento site page with Varnish VCL open. The editor shows the vcl_recv snippet, with tabs for vcl_backend_response, vcl_deliver and Platform VCL, and the buttons Save and Test._

2. **Write it, or insert one**

   Choose the tab of the hook your snippet runs in, **vcl_recv**, **vcl_backend_response** or **vcl_deliver**, and write your VCL. The **Snippets** tab beside the editor has ready-made ones: choose **Insert**.

   _Screenshot: The Varnish VCL editor with the Snippets panel open, listing ready-made snippets such as Bypass a path and Show the cache status, each with an Insert button._

3. **Test**

   Choose **Test**: it checks the snippets against the rules and compiles them on the site's Varnish version, without applying anything. If it finds errors, **Show problems** lists what to fix.

4. **Save and apply**

   Choose **Save**, enter a **Note** if you want one in **History**, then choose **Save and apply**. Tick **Purge everything once it is applied** to start from an empty cache.

The revision applies live. If Varnish cannot load it or the site stops answering with it, the previous revision is put back.

Your snippets run inside the platform's VCL. The **Platform VCL** tab shows it; it cannot be edited.

## Limits

|           |                                                                                                                   |
| --------- | ----------------------------------------------------------------------------------------------------------------- |
| Each hook | 16 KB and 200 statements.                                                                                         |
| All hooks | 48 KB.                                                                                                            |
| Rules     | **Test** checks the snippets against the rules every save must pass, and **Show problems** lists what breaks one. |

## Go back to an earlier revision

1. **Open History**

   Every save adds one revision. Choose **History** in the message **Varnish VCL saved**, which shows for 6 seconds after a save, or **Show history** in the message about a revision that was put back.

   _Screenshot: Varnish VCL History, listing each revision with when it was saved, by whom, its origin and its status._

2. **Revert**

   Choose **Revert to this** on the revision, then **Revert**. It is tested first, then saved as a new revision with the older content.

> **Note:** **Managed by Corefinity** on the section means support manages this environment's VCL. Contact support to change it.

## Automate this

**API:** [Replace a site's custom VCL](https://docs.corefinity.com/api/reference/varnish/replace-site-varnish-vcl.md), scope `write`

```bash
curl -X PUT https://manage.corefinity.com/api/corestack/sites/1042/varnish/vcl \
  -H "Authorization: Bearer $COREFINITY_TOKEN" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "hooks": {
      "backend_response": "if (bereq.url ~ \"^/size-guides/\") { set beresp.ttl = 1d; }"
    },
    "note": "Cache the size guides for a day",
    "version": 1
  }'
```

**MCP:** [`corestack_varnish_vcl_update`](https://docs.corefinity.com/mcp/tools/corestack_varnish_vcl_update.md), scope `write`

```json
{
  "name": "corestack_varnish_vcl_update",
  "arguments": {
    "site_id": 4211,
    "version": 5,
    "hooks": {
      "backend_response": "if (bereq.url ~ \"^/size-guides/\") {\n    set beresp.ttl = 1d;\n}\n"
    },
    "note": "Cache the size guides for a day"
  }
}
```

**Control Panel:** Managed Websites › your site › Site settings › Software & services ([https://manage.corefinity.com/go/varnish](https://manage.corefinity.com/go/varnish))

## Related

- [Varnish](/guides/sites/software-and-services/varnish): Switch Varnish on and purge its cache.
- [Web server rules](/guides/sites/site-settings/web-server-rules): Add your own nginx rules to a site.
- [Magento 2](/guides/platforms/magento-2): See what differs for Magento 2.
