Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I just started reading about Varnish and am considering using it as a frontend to my webservers. I have multiple domains on my webserver that fetch the same content when the same query strings are used. So lets say one client visits:

And later on, someone else visits:

Would Varnish cache the results from the first visit and use that for the second client? Thanks!

EDIT: After some more reading, it sounds like the following may work:

sub vcl_hash {
    set req.hash += req.url;
    return (hash);

So instead of added the variable to the hash, it ignores it.

share|improve this question
up vote 3 down vote accepted

You can configure it to do so, sort-of. By default, it won't (and shouldn't).

From Varnish FAQ/HowDoI

I have a site with many hostnames, how do I keep them from multiplying the cache?

You can do this by normalizing the "Host" header for all your hostnames. Here's a VCL example:

if ( ~ "^(www.)?") { set = ""; }

share|improve this answer
That or it's probably possible to strip the hostname entirely and just use the remainder of the path. YMMV. – Jauder Ho Jul 17 '09 at 11:11
Hmm, I added some code above that may work. If anyone can confirm, that'd be great! – Lin Jul 17 '09 at 18:06
I don't think (or don't hope) that Lin is asking about how to share the cache. The problem is that sharing the same data across urls on different sites could be a security/integrity issue. is NOT the same as Serving one when the other is asked for could be disastrous. – Lee B Jan 24 '10 at 15:58

I have 3 domains on my VM, I am using Nginx and Varnish, currently I am on a pre prod configuration, here what I am doing :

NGINX:80 ==> VARNISH:8080 ==> NGINX:8081

I am using Nginx:80 like a proxy IF the domain needs Varnish, if not, I use FastCGI stuff. In this exemple, the not Varnish sites are not concerned by Varnish. It looks stupid but it woks ;-) and none of my customers complain (yet....).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.