0

I know this question has been asked and answered a million times, but none of the accepted answers are working for me. My site is unreachable due to some sort of infinite redirect loop when I force all connections to https.

root /usr/share/nginx/html/flawedspirit.com/root_html;
index index.php index.html index.htm;

error_page 403 /index.php;
error_page 404 /error/404.php;
error_page 500 502 503 504 /error/50X.php;

access_log /usr/share/nginx/html/flawedspirit.com/logs/access.log;
error_log /usr/share/nginx/html/flawedspirit.com/logs/error.log;

server {
    listen 80 default_server;
    server_name flawedspirit.com;
    return 301 https://$server_name$request_uri;

    location ~ \.php {
        try_files $uri $uri/ =404;
        include fastcgi_params;
        fastcgi_pass php5-fpm-sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors on;
    }

    location ~ /\. {
        access_log off;
        log_not_found off;
        deny all;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|eot|woff|ttf|svg)$ {
        expires max;
        log_not_found off;
    }
}

server {
    listen 443 ssl;
    server_name flawedspirit.com;

    ssl on;
    ssl_certificate <...>;
    ssl_certificate_key <...>;
    ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers "ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4:HIGH:!MD5:!aNULL:!EDH:!AESGCM";
    ssl_prefer_server_ciphers on;
    ssl_ecdh_curve secp521r1;

    location ~ \.php {
        try_files $uri $uri/ @no-extension;
        include fastcgi_params;
        fastcgi_pass php5-fpm-sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTPS on;
        fastcgi_intercept_errors on;
    }

    location @no-extension {
        rewrite ^(.*)$ $1.php last;
    }

    location ~ /\. {
        access_log off;
        log_not_found off;
        deny all;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|eot|woff|ttf|svg)$ {
        expires max;
        log_not_found off;
    }
}

So what am I doing wrong?

3
  • There's nothing with your configuration that would cause the problem you describe. Check your application. Oct 6, 2014 at 18:56
  • It's worth noting that permanent redirects are that - permanent. It can help to turn the caching of those redirects off in your browser in case you're seeing the effect of previous configs seemingly being applied even if they are not present at the moment.
    – gparent
    Oct 6, 2014 at 18:58
  • I've cleared my cache several times, but it still dumps me on the error screen with ERR_TOO_MANY_REDIRECTS. Oct 6, 2014 at 19:02

2 Answers 2

2

Ok, so maybe it WAS a caching issue, just not in the first place I expected. I went to Cloudflare and nuked my site's cache there, and set my SSL setting to Full. That seemed to do it.

EDIT: I can't choose this as the answer for 48 more hours, so consider this the answer.

1

I really have a suspicion that the problem is here:

location @no-extension {
    rewrite ^(.*)$ $1.php last;
}

Doesn't it generate an infinite loop you are talking about? Because HTTP config seems to be ok and that location exists only in a HTTPS version. So try to connect straightly to https. You should get the same loop if i am correct.

2
  • I just removed the location block and the call to it, cleared my cache, and I still got the error. Oct 6, 2014 at 19:03
  • 1
    @Flawedspirit : Glueon is right, it will cause an infinite loop between the php and the fallback blocks if $uri and $uri/index.php are missing, ending up with a HTTP 500 error. It may not be your problem at the moment but it will be one day or another. Oct 6, 2014 at 19:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .