Varnish リダイレクト ループ

Varnish リダイレクト ループ

私は多くの varnish 構成を試しましたが、常に同じリダイレクト ループが発生し、varnish を数時間実行した後、一部のページにThe page isn't redirecting properlyfirefox で次のメッセージが表示されます。ここに画像の説明を入力してください

画像が示すように、最初のリクエストは 301 ステータス コードを返し、残りは 302 です。この 302 ステータス コードがどこから来たのかはわかりませんが、私の nginx 構成には次の内容があります。

# We don't want someone to visit a default site via IP
# So we catch all non-defined Hosts or blank hosts here
# the default listen will cause this server block to be used
# when no matching hostname can be found in other server blocks
server {
    # use default instead for nginx 0.7.x, default_server for 0.8.x+
    listen 81 default_server;
    # if no listen is specified, all IPv4 interfaces on port 80 are listened to
    # to listen on both IPv4 and IPv6 as well, listen [::] and 0.0.0.0 must be specified. 
    server_name _;
    return 301 $scheme://elbauldelprogramador.com$request_uri;
}

sites-enabled/mysite の場合:

server {
    listen 127.0.0.1:81;
    server_name www.elbauldelprogramador.com;
    return 301 $scheme://elbauldelprogramador.com$request_uri;
}
server {
    listen 127.0.0.1:81;
    server_name elbauldelprogramador.com

    #rest of configuration
}

おそらく、これらの 301 リダイレクトが問題なのでしょうか? 私の現在の varnish 構成は次のとおりです (ただし、これは私が証明したすべての構成で発生します)。

# Enter your backend Wordpress site here.
backend default {
    .host = "127.0.0.1"; # XXX CHANGE THIS
    .port = "81";        # (and maybe this)
    .connect_timeout = 60s;
    .first_byte_timeout = 60s;
    .between_bytes_timeout = 60s;
    .max_connections = 800;
}   

acl purge {
    "127.0.0.1";
}

# Drop any cookies sent to Wordpress.
sub vcl_recv {
    if (req.request == "PURGE") {
        if (!client.ip ~ purge) {
            error 405 "Not allowed.";
        }
        return (lookup);
    }

    if (req.http.host ~ "(?i)^(www.)?elbauldelprogramador.com") {
        set req.http.host = "elbauldelprogramador.com";
    }

    # Normalize encoding
    if (req.http.Accept-Encoding) {
        if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$") {
            # No point in compressing these
            remove req.http.Accept-Encoding;
        } elsif (req.http.Accept-Encoding ~ "gzip") {
            set req.http.Accept-Encoding = "gzip";
        } elsif (req.http.Accept-Encoding ~ "deflate") {
            set req.http.Accept-Encoding = "deflate";
        } else {
            # unknown algorithm
            remove req.http.Accept-Encoding;
        }
    }
    if (!(req.url ~ "wp-(login|admin|cron)")) {
        unset req.http.cookie;
    }
}

# Drop any cookies Wordpress tries to send back to the client.
sub vcl_fetch {
    if (!(req.url ~ "wp-(login|admin)")) {
        unset beresp.http.set-cookie;
    }
}

sub vcl_hit {
    if (req.request == "PURGE") {
        purge;
        error 200 "Purged.";
    }
}

sub vcl_miss {
    if (req.request == "PURGE") {
        purge;
        error 200 "Purged.";
    }
}

関連情報