Last Updated: February 25, 2016
· jtai

Testing Varnish VCL Syntax

I’ve been working with Varnish a lot this month. Since installing Varnish itself is pretty simple, “working with Varnish” usually means changing the VCL to get Varnish to behave the way you want it to. And if you’re editing VCL, you probably want to know if it compiles or not before you check it in or deploy it. Fortunately, there’s a command for that:

sudo varnishd -C -f /path/to/your.vcl

This will print out the VCL compiled as C code if the VCL is valid. If the VCL is not valid, an error message will be printed instead. For example, running this against a VCL file with no backends defined prints this error:

Message from VCC-compiler:
No backends or directors found in VCL program, at least one is necessary.
Running VCC-compiler failed, exit 1

Despite what the error message says about the exit code, Varnish always exits 0 — even if there’s an error. This bug has been fixed, but the fix is not part of the latest stable 3.0.2 release.

This tip was reposted from my blog,