清漆中的多个循环董事

时间:2017-11-27 09:25:28

标签: varnish

我想在单个清漆机器下配置桌面/移动网站。每个网站即移动版和桌面版都有多个Web服务器。所以我定义了多个导演,如下面

我正在使用清漆5.X

backend wap1 { .host = "xxx.xxx.xxx.xxx"; .port = "80"; 
.connect_timeout = 5s; .first_byte_timeout = 5s; .between_bytes_timeout = 2s; }
backend wap2 { .host = "xxx.xxx.xxx.xxx"; .port = "80"; 
.connect_timeout = 5s; .first_byte_timeout = 5s; .between_bytes_timeout = 2s; }

backend web1 { .host = "xxx.xxx.xxx.xxx"; .port = "80"; 
.connect_timeout = 5s; .first_byte_timeout = 5s; .between_bytes_timeout 
= 2s; }
backend web2 { .host = "xxx.xxx.xxx.xxx"; .port = "80"; 
.connect_timeout = 5s; .first_byte_timeout = 5s; .between_bytes_timeout 
= 2s; }

sub vcl_init {
new active_wap_rr = directors.round_robin();
new active_web_rr = directors.round_robin();
active_wap_rr.add_backend(wap1);
active_wap_rr.add_backend(wap2);
active_web_rr.add_backend(web1);
active_web_rr.add_backend(web2);
}

if (req.http.host == "m.example.com") {
    set req.backend_hint = active_wap_rr.backend();
}else if(req.http.host == "www.example.com" || req.http.host == "example.com") {
    set req.backend_hint = active_web_rr.backend();
}

现在,当我在桌面版中执行POST请求时,它会发送给移动站点主管,同时GET请求正常工作。

任何帮助或建议都将不胜感激。

由于

1 个答案:

答案 0 :(得分:0)

由于以下代码

,这种情况很糟糕
if (req.host == "m.example.com") {
    if(req.method == "POST"){
          return (pass);
    }
}else if (req.host == "www.example.com" || req.host == "example.com") {
      if(req.method == "POST"){
          return (pass);
      }
 }

以下代码指定后端提示

if (req.http.host == "m.example.com") {
    set req.backend_hint = active_wap_rr.backend();
}else if(req.http.host == "www.example.com" || req.http.host == 
"example.com") {
    set req.backend_hint = active_web_rr.backend();
}

在检查POST方法并返回传递给后端时,没有定义后端提示,因此它采用了第一个定义的后端。

正确的方法是

if (req.host == "m.example.com") {
    set req.backend_hint = active_wap_rr.backend();
    if(req.method == "POST"){
          return (pass);
    }
}else if (req.host == "www.example.com" || req.host == "example.com") {
      set req.backend_hint = active_web_rr.backend();
      if(req.method == "POST"){
          return (pass);
      }
 }

以下代码不需要分配后端。