varnish - 如何重定向特定的 url - Varnish?

标签 varnish varnish-vcl

抱歉,我是 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/

相关文章:

linux - 如何将 https 流量从一台 Web 服务器切换到另一台 Web 服务器。 IPTABLE问题

Varnish vcl 有选择地清除缓存

caching - Varnish 仅缓存特定的URL路径

varnish - 在清除或禁止操作时,Varnish 4是否使用哈希键查找对象?

Varnish 列出缓存中的所有 URL

Magento、Plesk 和 Varnish

angular - 在Varnish代理后面的Angular 5.6.0中设置文档根目录

apache - 无法在端口 80 Ubuntu 16.04 上启动 Varnish 缓存

varnish - 在Varnish 4中 'synthetic'设置了哪个变量?

varnish - 在 Varnish 4 中错误获取后,在 "probe"标记服务器不健康之前交付过时的内容