Varnish 调用后端主机的虚拟主机配置

代理后端一台主机内的多台虚拟主机配置

 

 Backends and virtual hosts in Varnish

Varnish fully supports virtual hosts. They might howeverwork in a somewhat counter-intuitive fashion since they are never declaredexplicitly. You set up the routing of incoming HTTP requests in vcl_recv. Ifyou want this routing to be done on the basis of virtual hosts you just need toinspect req.http.host.

 

You can have something like this:

 

sub vcl_recv {

    if(req.http.host ~ "foo.com") {

        setreq.backend_hint = foo;

    } elsif(req.http.host ~ "bar.com") {

        setreq.backend_hint = bar;

    }

}

Note that the first regular expressions will match"foo.com", "www.foo.com", "zoop.foo.com" and any other host endingin "foo.com". In this example this is intentional but you might wantit to be a bit more tight, maybe relying on the == operator in stead, likethis:

 

sub vcl_recv {

    if(req.http.host == "foo.com" || req.http.host == "www.foo.com") {

        setreq.backend_hint = foo;

    }

}

 

分割线
感谢打赏
江西数库信息技术有限公司
YWSOS.COM 平台代运维解决方案
 评论
 发表评论
姓   名:

Powered by AKCMS