Varnish with loadbalancer

varnish

Varnish has been applauded for various reasons. So, I am trying to setup varnish
in-front of loadbalancer, I am now able to setup varnish itself and which deals with
all incoming traffic and sends required ones towards web-server with brilliant amount of caching, limiting traffic and nice set of vcl config which has ability to filter traffic based on IP, location, User agent and so on.

However, I am not convinced with the logic of pointing VARNISH IP as A record for the given
domain's, (as I have around 15 domains).

Can someone kick my back and please enlighten me how can varnish be configured so that I can still point loadbalancer IP as A record.

In other word how can i setup varnish to serve caching objects but not as DNS entry Point.

All in all I am looking varnish to serve static content and other cache-able objects
(which is really high in number along with some json object which in my test environment has performed brilliantly).

[note: I am not configuring varnish as loadbalancer]

Best Answer

Assuming your load balancer and Varnish cache IP addresses are both available to the clients, what you could do is branch off a new subdomain for each of the main domains that is specifically used for cached assets (such as assets.domain.com).

You would continue to point domain.com and www.domain.com to the load balancer (as it is currently configured). Then separately, create the assets subdomains and configure them to use the Varnish cache. You may want to configure Varnish to cache objects only in certain folders or of certain types.

After manually testing that assets.domain.com returns the objects you intend, you would then replace links to your assets using the assets.domain.com instead of domain.com or www.domain.com so end clients would start using the cache.