Easily validating your Varnish cache VCL file and other quick tips

I’ve been playing around with varnish lately and had to make a change in a VLC file to perform URL re-writing before following with “hashing”, lookup, and if necessary forwarding to tomcat.
For anyone wanting further information on the varnish pipeline, as well as why someone should use varnish I recommend the following two articles:

1) http://open.blogs.nytimes.com/2010/09/15/using-varnish-so-news-doesnt-break-your-server/?smid=tw-share
2) https://www.varnish-software.com/static/book/VCL_Basics.html

Validating VCL

sudo varnishd -C -f /etc/varnish/default.vcl

The following will output a message with where a syntax error exists if there is any:

[5:52:40 μμ] Menios B: VCL compilation failed
[root@test varnish]# nano default.vcl
[root@test varnish]# sudo varnishd -C -f /etc/varnish/default.vcl
Message from VCC-compiler:
Wrong argument type.  Expected STRING.  Got IP.
(‘input’ Line 23 Pos 58)
set req.url = req.url + “co=” + geoip.country(client.ip);

Converting client.ip, server.ip, or other types to String

VCC compiler builds expressions left to right, so  seeing server.ip it has type “IP”, then you try to add a string to that  and it fails.
The workaround (see above) starts out with STRING, then adds IP, but since  everything, including IP, can be converted to string, that works out fine.

So, in the above error the solution is:
set req.url = req.url + “co=” + geoip.country(“”+client.ip);

If you have your own comments or tips please post below.
I will continue to provide more of these as I find them.

Menelaos Bakopoulos

Mr. Menelaos Bakopoulos is currently pursuing his PhD both at Center for TeleInFrastruktur (CTiF) at Aalborg University (AAU) in Denmark and Athens Information Technology (AIT) in Athens, Greece. He received a Master in Information Technology and Telecommunications Systems from Athens Information Technology and a B.Sc. in Computer Science & Management Information Systems from the American College of Thessaloniki. Since April 2008 he has been a member of the Multimedia, Knowledge, and Web Technologies Group.

More Posts