我需要使用Varnish
重定向大约10个子域。在线查看最简单的方法似乎是
sub vcl_recv {
if (req.http.host ~ "^(www\.)?oldexample\.com$") {
error 750 "http://www.example.com/newlocation";
} else if (req.http.host ~ "^(www\.)?ancientexample\.com$") {
error 750 "http://newsite.com/ancient";
}
}
sub vcl_error {
if (obj.status == 750) {
set obj.http.Location = obj.response;
set obj.status = 302;
return(deliver);
}
}
然而,在针对10个子域运行时,这似乎很浪费,特别是因为重定向是永久性的。我宁愿不针对多个if语句运行每个请求。对此有更好的varnish
替代方案吗?
答案 0 :(得分:0)
这是来自 varnish 站点的类似版本:https://varnish-cache.org/tips/vcl/redirect.html
sub vcl_recv {
if (req.url ~ "^/installation/ubuntu") {
return (synth(301, "/releases/install_ubuntu.html"));
}
if (req.url ~ "^/installation/debian") {
return (synth(302, "/releases/install_redhat.html"));
}
}
sub vcl_synth {
if (resp.status == 301 || resp.status == 302) {
set resp.http.location = resp.reason;
set resp.reason = "Moved";
return (deliver);
}
}