Caching Multiple Domain with Varnish

Varnish is an in-memory web accelerator server which helps Apache/Nginx server to run 10-300 times faster without spending anything on procuring hardware. Besides this It can also be used as a reverse proxy server.

In our projects we are using Varnish to cache the static content and in some cases we are also using it for caching the full pages in the memory. Few days back we got a requirement to cache multiple domain.

For one of the website we are also using “Directors” to group multiple backends, which gives us incresed performance and resilience.

## Following is a round robin director, which will be distributing the incoming requests on a round-robin basis. As we are also using the Health checks, so it will not send the incoming requests to unhealthy backend.
director prodweb round_robin {
{ .backend = web1; }
{ .backend = web2; }
}

Now we will edit the “vcl_recv” subroutine to hit the multiple backends as per our need.