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 is on. The Varnish VCL section shows only while it is.
Add a snippet
Open Varnish VCL
Go to Managed Websites, choose the site, then Varnish VCL under Site settings.
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.
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.
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
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.
Revert
Choose Revert to this on the revision, then Revert. It is tested first, then saved as a new revision with the older content.
Managed by Corefinity on the section means support manages this environment's VCL. Contact support to change it.
Automate this
Saves the snippets sent in hooks: a snippet left out stays as it is.
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
}'Your assistant calls corestack_varnish_vcl_update.
{
"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"
}
}