如何重定向特定 url - Varnish?

How to redirect on specific url - Varnish?

抱歉,我是 Varnish 的新手。

我在我的 /etc/varnish/mysite.vlc 中尝试了一堆东西,但无法让它工作。

我想在特定 url 上重定向到另一个 url。例子: 如果有人访问 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);
  }
}