Configure varnish to support multiple backend domain names
2011-07-12-web Development Tags: caching varnishIn the use of varnish will involve proxy multiple backend domain names (or Web sites), you can determine the requested URL to set the corresponding backend can solve the problem.
To varnish the official documentation of the example (Https://www.varnish-cache.org/docs/trunk/reference/vcl.html#examples):
#后端服务器www
backend www {
. host = "www.example.com";
. Port = "n";
#后端服务器images
backend Images {
. host = "images.example.com";
. Port = "n";
Sub Vcl_recv {
#如果host为www. example.com, set back-end server to WWW, (? i) to indicate that the matching pattern is case-insensitive
if (req.http.host ~ "(? i) ^ (www.)? example.com$ ") {
set req.http.host =" www.example.com ";
Set req.backend = www;
#如果为images. example.com, set back-end server to images
} elsif (req.http.host ~ "(? i) ^images.example.com$") {
set Req.backend = images;
} else {
error 404 ' Unknown virtual host ';
}
}
Also in the Vcl_hash function must be added
Hash_data (Req.http.host);