抱歉,我是 Varnish 的新手。
我正在我的 /etc/varnish/mysite.vlc 中尝试一堆东西,但无法让它工作。
我想将特定网址重定向到另一个网址。例子:
如果有人访问 http://mysite1/thepage1.xml
它应该去 http://mysite2/thepage2.xml
varnishd -V
varnishd (varnish-3.0.5 revision 1a89b1f)
Copyright (c) 2006 Verdens Gang AS
Copyright (c) 2006-2011 Varnish Software AS
如有任何帮助,我们将不胜感激。
最佳答案
如何在 Varnish 3 中重定向
sub vcl_recv {
if (req.url~ "^/thepage1.xml?$") {
error 750 "http://mysite2/thepage2.xml";
}
}
sub vcl_error {
if (obj.status == 750) {
set obj.http.Location = obj.response;
set obj.status = 301;
return(deliver);
}
}
如何在 Varnish 4 中重定向
sub vcl_recv {
if (req.url~ "^/thepage1.xml?$") {
return (synth (750, "http://mysite2/thepage2.xml")); #This throws a synthetic page so the request won't go to the backend
}
}
sub vcl_synth {
if (resp.status == 750) {
set resp.http.Location = resp.reason;
set resp.status = 301;
return(deliver);
}
}
关于varnish - 如何重定向特定的 url - Varnish?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36195325/