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,

The basic setup is as following:

Read More
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)

I added the full config in a 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.

Is there anyone that has experience with this happening and can suggest what to do?

Related posts

1 comment

  1. Old question, but try modifying the vcl_hash subroutine. This worked for me on a single site, that included multiple redirects for http -> https and domain.com -> http://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.

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

Comments are closed.