直接在vcl_recv中修改后端主机?

时间:2015-03-15 20:03:38

标签: varnish varnish-vcl

我可以直接在vcl_recv中提及后端主机吗?

   sub vcl_recv{
       if (req.http.host=="www.yourdomain.com.a-free-cdn.com") {
           set req.http.host = "www.yourdomain.com";
           set req.backend.host = "www.yourdomain.com";
       }
   }

如果无法做到这一点,是否有其他方法可以做到这一点?实际上,我事先并不知道有关后端的任何事情。

1 个答案:

答案 0 :(得分:4)

是的我认为您在req.backend req.backend_hint语法中提到vcl_recv() / backend www { .host = "www.example.com"; .port = "http"; } sub vcl_recv { if (req.http.host ~ "(?i)^(www.)?example.com$") { set req.backend = www; } }

backend www {
  .host = "www.example.com";
  .port = "http";
}

sub vcl_recv {
  if (req.http.host ~ "(?i)^(www.)?example.com$") {
    set req.backend_hint = www;
  }
}

并使用Varnish 3语法:

{{1}}