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

i have two web web sites and i want to cache them with varnish. could i cache them on same varnish with using same port?

for example; www.domain1.com:80, www.domain2.com:80

share|improve this question

2 Answers 2

If your backends are different for each of the domains, you can do something like the following.

backend domaina_com {
.host = "1.2.3.4";
.port = "80";
}
backend domainb_com {
.host = "2.3.4.5";
.port = "80";
}

sub vcl_recv {
 if (req.http.host ~ "^domaina.com$") {
   set req.backend = domaina_com;
 }
 if (req.http.host ~ "^domainb.com$") {
   set req.backend = domainb_com;
 }

If your domains are on the same backend, it is just a matter of making sure that the .host that you connect to answers the request properly. i.e. NameVirtualHost 127.0.0.1:80 and make sure the configs for the domains are set to answer on 127.0.0.1:80.

share|improve this answer
    
It's important that you get the hostname checks right, since hosts could be in mixed case etc. Don't rely on the client behaving like a well-trained browser! –  Christian Davén May 16 '11 at 8:04

Yes you can. Varnish is a reverse caching proxy. It will cache any number of web-sites configured as back-ends.

share|improve this answer

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.