Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have one VPS serving 2 Wordpress installations. Using Varnish > Nginx > PHP-FPM Right now I have this in the conf.d folder of nginx:

domain1.com.conf domain2.com.conf

A configuration example for one domain goes like this:

server {
    server_name domain1.com www.domain1.com *.domain1.com;
    listen 127.0.0.1:81;
    expires max;
    root /home/domain1.com;

    index index.php;

The default VCL file for Varnish:

backend default {
  .host = "127.0.0.1";
  .port = "81";
  .connect_timeout = 600s;
    .first_byte_timeout = 600s;
    .between_bytes_timeout = 600s;
}

All the domains have the same listen value, 127.0.0.1:81.

How do I make Varnish to actually serve the cached version of the right domain?

share|improve this question
    
Varnish will serve whatever content is requested, the mechanics of the back-end server are not that important to it. It looks at the host header and the details of the request. If you want specific control over the process, in sub vcl_recv(), use a regex matching your domain against req.http.Host (and then add whatever additional processing you want - e.g. modifying cookies). You can also do the same in vcl_fetch() do the same, modifying the headers (for example) of the content that is served. –  cyberx86 Dec 19 '11 at 3:58
    
This has been asked on stackoverflow, and has another resolution. Check the answer: stackoverflow.com/a/3397592 –  Paul Dec 19 '11 at 18:54

1 Answer 1

up vote 1 down vote accepted

To split your cache by domain name change your VCL configuration with next: add this to vcl_hash subroutine:

for varnish 2.1.x

if (req.http.host) {
 set req.hash += req.http.host;
}
else {
 set req.hash += server.ip;
}

for varnish 3.x

if (req.http.host) {
 hash_data(req.http.host);
}
else {
 hash_data(server.ip);
}
share|improve this answer
    
The default.vcl (lines 84-92) already includes that (at least for Varnish 3.x) - but +1 for hashing –  cyberx86 Dec 19 '11 at 6:18
    
I find that doesn't work out of the box. I may have some problems with cloudflare's caching service. I will try it now and report it back in a couple of hours. –  user104531 Dec 19 '11 at 12:29
    
Cloudflare has to be disabled to don't cache the old version of your website while development. Also, having the last Varnish version helps. –  user104531 Dec 19 '11 at 14:05

Your Answer

 
discard

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.