Difference between revisions of "Setup Varnish - Multiple Domains"

From Brian Nelson Ramblings
Jump to: navigation, search
(Created page with "==Setup Varnish for Multiple Domains== Many times you will have on instance of Varnish on your server but you will have multiple domains on your server. You will need to crea...")
 
(Setup Varnish for Multiple Domains)
 
(One intermediate revision by the same user not shown)
Line 28: Line 28:
 
  }
 
  }
  
 +
If you need to setup one of your domains to listen for both www and non-www
 +
 +
if (req.http.host ~ "^(www\.)?briansnelson\.com$") {
 +
        set req.http.host = "briansnelson.com";
 +
        set req.backend = example2;
 +
        return (lookup);
 +
}
 +
 +
If you need the setup to be used for any sub-domain
 +
 +
if (req.http.host ~ "^(.*\.)?briansnelson\.com$") {
 +
        set req.http.host = "briansnelson.com";
 +
        set req.backend = example2;
 +
        return (lookup);
 +
}
 
===Additional Articles===
 
===Additional Articles===
 +
* [[Setup Varnish Cache]]
 +
* [[Setup Varnish for Magento]]
 +
* [[Setup Varnish for Wordpress]]
 +
* [[Setup Varnish for MediaWiki]]
 +
* [[Setup Varnish - Multiple Ipaddress]]
 +
*[[Script to Clear a Page from Varnish Cache]]

Latest revision as of 16:51, 13 March 2014

Setup Varnish for Multiple Domains

Many times you will have on instance of Varnish on your server but you will have multiple domains on your server. You will need to create separate backends for each domain.

Below is an example of using two separate domains, with different internal ip.

backend example1 {
    .host = "127.0.0.1";
    .port = "81";
}
backend example2 {
     .host = "127.0.0.2";
     .port = "81";
}
sub vcl_recv {
   if (req.http.host == "example1.com") {
       #You will need the following line only if your backend has multiple virtual host names
       set req.http.host = "example1.com";
       set req.backend = example1;
       return (lookup);
   }
   if (req.http.host == "example2.com") {
       #You will need the following line only if your backend has multiple virtual host names
       set req.http.host = "example2.com";
       set req.backend = example2;
       return (lookup);
   }
}

If you need to setup one of your domains to listen for both www and non-www

if (req.http.host ~ "^(www\.)?briansnelson\.com$") {
       set req.http.host = "briansnelson.com";
       set req.backend = example2;
       return (lookup);
}

If you need the setup to be used for any sub-domain

if (req.http.host ~ "^(.*\.)?briansnelson\.com$") {
       set req.http.host = "briansnelson.com";
       set req.backend = example2;
       return (lookup);
}

Additional Articles