使用 Varnish 配置多个站点 [英] Configure multiple sites with Varnish
本文介绍了使用 Varnish 配置多个站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们有一个服务器需要通过清漆为多个域提供服务,例如example1.com、example2.com 和 example3.com
We have a server which needs to serve multiple domains though varnish e.g. example1.com, example2.com and example3.com
我们当前的 .vcl 文件如下所示:
Our current .vcl file looks like this:
sub vcl_recv {
set req.http.Host = "example1.com";
lookup;
}
如何为正确的传入请求设置正确的 req.http.Host?
How do I set the correct req.http.Host for the correct incoming request?
推荐答案
您可以通过这种方式支持多个前端域:
You can support multiple frontend domains this way:
backend example1 {
.host = "backend.example1.com";
.port = "8080";
}
backend example2 {
.host = "backend.example2.com";
.port = "8080";
}
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 = "backend.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 = "backend.example2.com";
set req.backend = example2;
return (lookup);
}
}
这篇关于使用 Varnish 配置多个站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文