【问题标题】:Varnish returning error too many redirects清漆返回错误太多重定向
【发布时间】:2016-01-01 19:03:58
【问题描述】:

我正在尝试让 Varnish 使用博客缓存两个不同的域,但是在添加第二个域后,前一个域停止工作,

基本设置如下:

backend default {
    .host = "127.0.0.1";
    .port = "81";
}
backend onedomain {
    .host = "127.0.0.1";
    .port = "81";
}
backend newdomain {
    .host = "127.0.0.1";
    .port = "81";
}

acl purge {
    "localhost";
}

sub vcl_recv {
    # Happens before we check if we have this in cache already.
    #
    # Typically you clean up the request here, removing cookies you don't need,
    # rewriting the request, etc.

    #Bypass large files
    if (req.http.x-pipe-mark && req.restarts > 0) {
        return(pipe);
    }

    # all domains in here will return a "pass" which means they won't be cached
    if (req.http.host ~ "(www\.)?(domain1.com|domain2.com)") {
        return (pass);
    }
    #else check if something we're going to cache
    else if(req.http.host ~ "(www\.)?(onedomain.nu)") {
        set req.http.host = "onedomain.com";
        set req.backend_hint = onedomain;
    }
    else if(req.http.host ~ "(www\.)?(newdomain.com)") {
        set req.http.host = "newdomain.com";
        set req.backend_hint = newdomain;
    }
    else {
        return (pass);
    }

Newdomain 加载正常,而 domain4 只是将我发送到无限重定向循环(根据 chrome 错误)

我在 pastebin 中添加了完整的配置:http://pastebin.com/J1Hb76dZ

我意识到 Varnish 本身不会发送任何重定向命令,该站点使用旧配置,只有当我尝试此操作时,其中一个网站才会出现重定向问题。

有没有人遇到过这种情况并可以建议怎么做?

【问题讨论】:

    标签: wordpress apache caching blogs varnish


    【解决方案1】:

    老问题,但尝试修改 vcl_hash 子例程。这在一个站点上对我有用,其中包括 http -> https 和 domain.com -> www.domain.com 的多个重定向。它还应该配置哈希以区分您的不同域,因为这对于我将所有重定向与导致可怕的“重定向过多”错误的站点数据分开存储是必要的。由于我在负载均衡器后面,您可能需要调整/删除 X-Forwarded-Proto 标头。

    sub vcl_hash {
        hash_data(req.http.host);
        hash_data(req.url);
        hash_data(req.http.X-Forwarded-Proto);
        return(hash);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-13
      • 2016-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-11
      • 2017-06-02
      • 2017-01-23
      相关资源
      最近更新 更多