简体   繁体   English

清漆返回错误,重定向过多

[英]Varnish returning error too many redirects

I'm attempting to get Varnish to cache two different domains with blogs, but upon adding the second one, the previous one stops working, 我正在尝试让Varnish在博客中缓存两个不同的域,但是在添加第二个域之后,前一个域便停止工作,

The basic setup is as following: 基本设置如下:

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 loads fine while domain4 just sends me to an infinite redirect loop (according to the chrome error) Newdomain加载正常,而domain4只是将我发送到无限重定向循环(根据chrome错误)

I added the full config in a pastebin: http://pastebin.com/J1Hb76dZ 我将完整的配置添加到了pastebin中: http : //pastebin.com/J1Hb76dZ

I realize Varnish doesn't send any redirect commands itself, the site works on the old configuration, it's only when I try this that the redirect issue arises on one of the websites. 我意识到Varnish本身不会发送任何重定向命令,该站点可以在旧配置上运行,只有当我尝试这样做时,其中一个站点上才会出现重定向问题。

Is there anyone that has experience with this happening and can suggest what to do? 是否有人对此事有经验并可以提出建议?

Old question, but try modifying the vcl_hash subroutine. 旧问题,但是尝试修改vcl_hash子例程。 This worked for me on a single site, that included multiple redirects for http -> https and domain.com -> www.domain.com. 这对我来说在一个站点上起作用,其中包括http-> https和domain.com-> www.domain.com的多个重定向。 It should also configure the hash to tell your different domains apart, as that was necessary for me to store all the redirects separate from the site data that caused the dreaded "too many redirects" errors. 它还应该配置哈希值,以区分您的不同域,因为这对于我将所有重定向存储与导致可怕的“太多重定向”错误的站点数据分开存储是必需的。 You may need to adjust/remove the X-Forwarded-Proto header as I am behind a load balancer. 您可能需要调整/删除X-Forwarded-Proto标头,因为我位于负载均衡器的后面。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM