Table of Contents


Varnish is a web accelerator.

Wikipedia: A web accelerator is a proxy server that reduces web site access times. They can be a self-contained hardware appliance or installable software.


Edit /etc/varnish/default.vcl:

backend default {
  .host = "";
  .port = "80";

The web server must accept connections on that IP address and serve the content. A standard virtualhost would listen only on public IP addresses.

Start varnishd:

varnishd -f /etc/varnish/default.vcl -s malloc,1G -T -a


  • Varnish can have several backends defined and can you can even join several backends together into clusters of backends for load balancing purposes.
  • Be aware that every object that is stored also carries overhead that is kept outside the actually storage area. So, even if you specify -s malloc,16G varnish might actually use double that. Varnish has a overhead of about 1k per object. So, if you have lots of small objects in your cache the overhead might be significant.
  • You can use Varnish to cache content from different servers, effectively splitting URLs across many backends. Fex: http://domain/ pulls from while http://domain/images/ pulls from
  • Varnish has a “saint mode” where it will only send a cache if there is a bad request returnedV from the original webserver. Fex: Site returns HTTP 500 because it is overloaded, so Varnish serves stale content. See: here
  • Varnish can act as a high availability server, balancing load between two backends. Fex: Two servers on different IP addresses are handling the backend load. See: here


curl | apt-key add -
echo "deb lucid varnish-3.0" >> /etc/apt/sources.list
apt-get update
apt-get install varnish