This example assumes you have a VCL file in the Varnish Controller. If you are looking on how to add a VCL to the Varnish Controller please refer to this example: Deploying VCL Files.
We are going to make some changes to an existing VCL. For information about VCL please refer to our developer portal. Below is an example VCL that is currently added in the Varnish Controller in this example.
vcl 4.1;
backend default {
.host = "127.0.0.1";
.port = "80";
}
sub vcl_recv {
if (req.url == "/varnish-ping") {
return(synth(200));
}
if (req.url == "/varnish-ready") {
return(synth(200));
}
}
Editing a VCL with the CLI is pretty easy. First we need to figure out the ID of the VCL we want to edit. We do this by running the vcli file list
command.
$ vcli file list
+----+----------+-------+---------------------------+-----+----------------+---------+
| ID | Name | State | Content | SHA | Organization | Creator |
+----+----------+-------+---------------------------+-----+----------------+---------+
| 1 | test.vcl | New | text/plain; charset=utf-8 | | [System Admin] | test(1) |
+----+----------+-------+---------------------------+-----+----------------+---------+
Now that we have the ID of the VCL we want to edit, we can run the command vcli file edit 1
where 1
is the ID of the VCL we want to edit.
If there is already an edited (draft) version of the file in the Varnish Controller you will get a question what you want to do with it.
Answer with y
in order to continue editing the edited file, this is the default option. Use n
to discard the current changes and edit the original state of the VCL or use d
to see the differences between the original and edited (draft) version of the VCL.
$ vcli file edit 1
There is a draft version of the file, would you like to continue editing? Use d for diff. (Y/n/d):
After answering with y
or n
the default editor of the system will open, make your changes to the VCL, save and exit the editor. The CLI will ask you if you want to save the changes, enter y
to store the changes in the Varnish Controller and n
to discard them.
Save edited vcl as draft? (y/N):
Changes to VCLs are not automatically deployed, in order to deploy the changes to Varnish you will need to deploy your VCLGroup. This can be accomplished by the command vcli vg deploy 1
where 1
is the ID of the VCLGroup to be deployed.
A VCLGroup that has a VCL that is shared between VCLGroups will automatically trigger a deployment of all VCLGroups that use the VCL.
In the UI we go to the Editor
. Click on the file you whish to edit. At the top right next to the arrow buttons there is a save button. A VCL can also be edited when editing a VCLGroup.
Changes to VCLs are not automatically deployed, in order to deploy the changes to Varnish you will need to deploy your VCLGroup. Go to the VCLGroup you want to deploy and hit the Save & Deploy
button.
A VCLGroup that has a VCL that is shared between VCLGroups will automatically trigger a deployment of all VCLGroups that use the VCL.