0

I've tried with a lot of varnish configurations and always experience the same redirect loop, after varnish is running for a couple of hours some pages are displaying the message: The page isn't redirecting properly in firefox. enter image description here

As the image shows, the first request return a 301 status code, the rest are 302, I have no idea from where this 302 status code are, in my nginx config I have:

# 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;
}

In 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
}

Maybe those 301 redirect are the problem?, My current varnish config is this (Although it happens with all config I had prove.)

# 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.";
    }
}
8
  • What's the Location being sent with the 302? What content or application is Varnish in front of (since that's where the 302s are coming from)? Jan 13, 2014 at 0:12
  • I have nginx behind varnish on port 81, but in my config I do not have any 302 redirections, neither nginx or varnish are sending 302. After the first request, with 301 redirect, the url is domain.com/original-request-url/404. I do not know if for Location you mean this. Thank you Jan 13, 2014 at 10:43
  • What application is running within nginx? Location is the HTTP header sent with the 30x responses, it's visible in your image but for the 301 only (and not the complete URL). Jan 13, 2014 at 16:38
  • Wordpress, the Location header for the 301 is elbauldelprogramador.com/… and for the rest is elbauldelprogramador.com/… Jan 13, 2014 at 16:55
  • Is http://elbauldelprogramador.com/crear-formularios-en-django-partir-de-un-modelo-con-modelform/ a valid page if you hit wordpress directly? Wordpress is apparently trying to redirect to some kind of 404 page. Jan 13, 2014 at 17:27

0

You must log in to answer this question.

Browse other questions tagged .