Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloudflare and nginx: Too many redirects

Tags:

I'm trying to set up NGINX and cloudflare. I've read about this on Google but nothing solved my problem. My cloudflare is active at the moment. I removed all page rules in cloudflare but before had domain.com and www.domain.com to use HTTPS. I thought this could be causing the problem so I removed it. Here is my default NGINX file, with purpose of allowing only access by domain name and forbid access by IP value of the website:

server{    #REDIRECT HTTP TO HTTPS    listen 80 default;   listen [::]:80 default ipv6only=on; ## listen for ipv6   rewrite ^ https://$host$request_uri? permanent;  }  server{    #REDIRECT IP HTTPS TO DOMAIN HTTPS             listen 443;     server_name numeric_ip;     rewrite ^ https://www.domain.com;   }  server{    #REDIRECT IP HTTP TO DOMAIN HTTPS      listen 80;     server_name numeric_ip;     rewrite ^ https://www.domain.com;  }  server {           listen 443 ssl;          server_name www.domain.com domain.com;          #rewrite ^ https://$host$request_uri? permanent;          keepalive_timeout 70;           ssl_certificate     /ssl/is/working.crt;          ssl_certificate_key /ssl/is/working.key;           ssl_session_timeout 1d;          ssl_session_cache shared:SSL:50m;           #ssl_dhparam /path/to/dhparam.pem;           ssl_protocols TLSv1 TLSv1.1 TLSv1.2;          ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM$          ssl_prefer_server_ciphers on;           add_header Strict-Transport-Security max-age=15768000;           (...) more ssl configs 

What could be off? I'll provide mroe information if needed...

like image 703
Fane Avatar asked Feb 02 '16 00:02

Fane


People also ask

Why do I keep getting redirected to Cloudflare?

The two typical causes of redirect loop errors are: Cloudflare SSL options that are incompatible with your origin web server's configuration, and. Page Rule misconfiguration.

What causes too many redirects?

The reason you see the “too many redirects” error is because your website has been set up in a way that keeps redirecting it between different web addresses. When your browser tries to load your site, it goes back and forth between those web addresses in a way that will never complete — a redirect loop.

How do I force https Cloudflare?

To enable Always Use HTTPS in the dashboard: Log in to your Cloudflare account Open external link and go to a specific domain. Navigate to SSL/TLS > Edge Certificates. For Always Use HTTPS, switch the toggle to On.


1 Answers

After tryouts I found that this is only related to Cloudflare. Because I had no redirect problem before moving to Cloudflare.

In my case it was a simple fix like this. Select [Crypto] box and select Full (strict) as in the image.

enter image description here

Really, you can try this out first before any other actions.

like image 57
prosti Avatar answered Sep 28 '22 23:09

prosti