Varnish 重定向循环

Varnish 重定向循环

我尝试了很多 varnish 配置,总是遇到相同的重定向循环,在 varnish 运行几个小时后,一些页面会The page isn't redirecting properly在 Firefox 中显示消息:在此处输入图片描述

如图所示,第一个请求返回 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.";
    }
}

相关内容