Multiple virtual hosts via Varnish, incorrect backend if served <p>I have several backends set up, each one is detected in the VCL and then the correct set up applied. This works for some of the sites, but a few get pointed to the same site. </p> <p>I have read this and applied this, it works for some, but not for others.</p> <p><a href="http://stackoverflow.com/questions/3334023/configure-multiple-sites-with-varnish">Configure multiple sites with Varnish</a></p> <p>For example I have some backends defined:</p> <pre><code>backend site4 { .host = "127.0.0.1"; .port = "81"; } backend site3 { .host = "127.0.0.1"; .port = "81"; } backend site2 { .host = "127.0.0.1"; .port = "81"; } backend site1 { .host = "127.0.0.1"; .port = "81"; } </code></pre> <p>Then in <code>vcl_recv</code> I set the host and the correct backend:</p> <pre><code>if (req.http.host ~ "(?i)^(www.)?site1.co.uk") { set req.http.host = "www.site1.co.uk"; set req.backend = site1; } elsif (req.http.host ~ "(?i)^(www.)?site2.co.uk") { set req.http.host = "www.site2.co.uk"; set req.backend = site2; } elsif (req.http.host ~ "(?i)^(www.)?site3.com") { set req.http.host = "www.site3.com"; set req.backend = site3; } elsif (req.http.host ~ "(?i)^(www.)?site4.net") { set req.http.host = "www.site4.net"; set req.backend = site4; } </code></pre> <p>www.site1.co.uk works, as does www.site2.co.uk, but www.site3.com and www.site4.net both show the content for www.site2.co.uk - it's like its ignoring my backend and just using the same one for certain sites.</p> <p>The host is set correctly, because if I do:</p> <pre><code>curl -I http://site3.com </code></pre> <p>when using the following in <code>vcl_fetch</code></p> <pre><code>set beresp.http.X-Host = req.http.host; </code></pre> <p>I can see the host is correctly set as www.site3.com</p> <p>Any ideas anyone?</p> <p>Side note, is there a shorter method of defining my backends?</p>