Jan 15 2015
Redirecting varnish to new backend on the fly
1) 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:
- https://www.varnish-cache.org/docs/trunk/users-guide/vcl-backends.html
- http://maythesource.com/2013/01/18/easily-validating-your-varnish-cache-vcl-file-and-other-quick-tips/
- http://technosophos.com/2010/09/09/varnish-reloading-vcl-configuration-files-varnishadm.html
- http://giantdorks.org/alain/exploring-methods-to-purge-varnish-cache/