Varnish with multiple sites/boxes

Posted by jerhinesmith on Server Fault See other posts from Server Fault or by jerhinesmith
Published on 2011-01-03T17:06:09Z Indexed on 2011/01/03 17:55 UTC
Read the original article Hit count: 250

Filed under:
|
|

Is it possible for Varnish to redirect traffic to different IPs based on the url?

For example, is the following setup feasible (and if so, what would the VCL look like):

  1. *.example.com points to Varnish IP address
  2. When a request is made to foo.example.com, varnish checks the cache and sends the request to Server1's IP address on a cache miss.
  3. When a request is made to bar.example.com, varnish checks the cache and sends the request to Server2's IP address on a cache miss.

foo and bar are (for the most part) completely unrelated sites. They use the engine, but have different content and their own distinct database. Since there previously was no penalty for doing so (other than cost) we split them up into two separate boxes so that a ton of traffic to foo won't have a negative impact on visitors browsing around bar.

I could set up two instances of varnish and have one serve up foo's static content and the other serve up bar's, but as there doesn't seem to be much overhead to running Varnish, I think (perhaps mistakenly) that it would make more sense to go with one Varnish server that redirects the traffic to the appropriate box on a cache miss.

© Server Fault or respective owner

Related posts about cache

Related posts about varnish