Varnish 后端主机直接在 vcl_recv?
Varnish backend host directly in vcl_recv?
我可以在 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";
}
}
如果这不可能,是否有替代方法?其实,我事先对后端一无所知。
是的,我认为您指的是 vcl_recv()
中的 req.backend
/req.backend_hint
,Varnish 3 语法:
backend www {
.host = "www.example.com";
.port = "http";
}
sub vcl_recv {
if (req.http.host ~ "(?i)^(www.)?example.com$") {
set req.backend = www;
}
}
并且在 Varnish 4 语法中:
backend www {
.host = "www.example.com";
.port = "http";
}
sub vcl_recv {
if (req.http.host ~ "(?i)^(www.)?example.com$") {
set req.backend_hint = www;
}
}
我可以在 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";
}
}
如果这不可能,是否有替代方法?其实,我事先对后端一无所知。
是的,我认为您指的是 vcl_recv()
中的 req.backend
/req.backend_hint
,Varnish 3 语法:
backend www {
.host = "www.example.com";
.port = "http";
}
sub vcl_recv {
if (req.http.host ~ "(?i)^(www.)?example.com$") {
set req.backend = www;
}
}
并且在 Varnish 4 语法中:
backend www {
.host = "www.example.com";
.port = "http";
}
sub vcl_recv {
if (req.http.host ~ "(?i)^(www.)?example.com$") {
set req.backend_hint = www;
}
}