使用Varnish更改后端的URL但不更改客户端的URL

时间:2013-02-14 16:00:28

标签: url varnish varnish-vcl

我想操纵客户端网址“www.example.com/download ..”到“one.other.com/download ... 但我希望客户端上的网址保留第一个“www.example.com/download”

Varnish 3有没有办法做到这一点?

1 个答案:

答案 0 :(得分:4)

是的,您可以使用regsub()中VCL中的vcl_recv功能轻松完成此操作。

例如:

if (req.http.host ~ "^(www\.)?example\.com" && req.url~ "^/download/") {
  set req.http.host = "one.other.com";
  set req.url = regsub(req.url, "^/download/", "/");
} 

此示例重写了对http://www.example.com/download/example.jpghttp://one.other.com/example.jpg的访问权限。当然,用户看不到它。