0
其實我的設置看起來像這樣。使用命名虛擬主機進行Varnish循環負載均衡
cluster.com - 192.168.0.200 (varnish/port 80)
example.com - 192.168.0.100 (apache,namebased vhost/8080 - backendname - website)
yyy.com - 192.168.0.100 (apache,namebased vhost/8080 -backendname - api)
cluster.com is the varnish server and front-end connections coming to this and rewrite to other defined back-ends (round-robin based balancing)
backend website {
.host = "example.com";
.port = "8080";
}
backend api {
.host = "yyy.com";
.port = "8080";
}
director clust round-robin {
{ .backend = api; }
{ .backend = website; }
}
sub vcl_recv {
set req.backend = clust;
if (req.request)
{
return(pass);
}
}
when i hit the cluster.com , it is always going to example.com, but what i need to do is first request go to example.com second request yyy.com and so on...when i add another server (different host/different IP say 192.168.0.111/zzz.com, and a different backend) , it goes like this
first request - example.com
second request - examplee.com
third request - zzz.com
but i can change the default behavior by setting up set req.host = yyy.com and then it will goes to
first request - yyy.com
second request - yyy.com
third request - zzz.com
這與主機頭轉發到正確的後端有關。我應該如何將該功能添加到vcl_recv? 感謝您對此的幫助,這與其他服務器(不同服務器,不使用基於名稱的虛擬主機)完美配合。
感謝您的回覆,但我的問題是後端連接到相同的IP地址。如果您解決xxx.com和yyy.com,則兩者都將解析爲192.168.0.100。不知道這是可能的清漆。歡呼聲, –
正如我所說,除非指示,否則Varnish不關心主機名稱。因此,清漆會將「主機」標頭傳遞給Apache,因爲設置在Varnish中的後端能夠處理相應的主機,所以它會正常工作。我會編輯我的回覆,試圖澄清一點。 – NITEMAN