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.
I have read this and applied this, it works for some, but not for others.
Configure multiple sites with Varnish
For example I have some backends defined:
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";
}
Then in vcl_recv I set the host and the correct backend:
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;
}
http://www.site1.co.uk works, as does http://www.site2.co.uk, but http://www.site3.com and http://www.site4.net both show the content for http://www.site2.co.uk – it’s like its ignoring my backend and just using the same one for certain sites.
The host is set correctly, because if I do:
curl -I http://site3.com
when using the following in vcl_fetch
set beresp.http.X-Host = req.http.host;
I can see the host is correctly set as http://www.site3.com
Any ideas anyone?
Side note, is there a shorter method of defining my backends?
For the sites that had not worked I had not added the new Apache port to the VirtualHost entry
I had
It needed to be
To work on the new Apache port