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...")
(No difference)

Revision as of 05:39, 19 January 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);
   }
}

Additional Articles