Redirecting varnish to new backend on the fly

varnishCache1) Change VCL backend config

Go to your vcl file (in my case /etc/varnish/default.vcl). Edit the backend param to point to another server. Also increase the timeouts since it will take longer than accessing localhost.

backend default {
 .host = "backupserver.org";
 .port = "80";
 .connect_timeout = 120s;
 .first_byte_timeout = 600s;
 .between_bytes_timeout = 60s;
}

2) Validate VCL script on the fly

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

This will notify if any syntax issues exist.

 

3) Reload the VCL Script without restarting varnish

I utilized:

$varnishadm -T localhost:6082
vcl.load reload01 /etc/varnish/default.vcl 
vcl.use reload01


If you get an error “Authentication Required” you have a newer version of varnish and need a secret file for auth. Also, the default port is 6082 but you will have to check your varnish config if that does not work.

sudo varnishadm -T 127.0.0.1:6082 -S /etc/varnish/secret

More Resources

The following articles include further information:



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