Search

Change a VCL file

Change a VCL file

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.

Editing 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 | Dir |   Name    | Label |  Organization  | Creator |
+----+-----+-----------+-------+----------------+---------+
| 1  |     | test1.vcl |       | [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.

When saving the changes, you will get a question about saving the file as a new version. Answer y to save as a new version. This will create a new version of the file. All changes to files will end up in a new version. The file itself never has a source, only one or more versions.

$ vcli file edit 1

Save edited file as a new version? (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.

When a VCLGroup is marked to track latest changes, the change of the file will automatically deploy the VCLGroups that uses this file. VCLGroups that is not marked with tracking latest changes, will not be deployed automatically and keep using the previous version deployed for each VCLGroup.

In the UI we go to the Editor. Click on the file you whish to edit. At the top right there is a save button, this will create a new version of the file you just edited.

image alt >

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, navigate to Deploy & Compile and select versions to deploy.


®Varnish Software, Wallingatan 12, 111 60 Stockholm, Organization nr. 556805-6203