Ubuntu: Using SSL with redirects from non http causes redirect loop?


I recently setup letsencrypt with my site, and the SSL works perfectly. However, when I set Nginx to redirect HTTPS to HTTPS, I get a redirect loop where when you visit the website and refresh the URL changes back and forth from example.com to https://example.com.

This is my configuration:

server {      listen 80;      server_name example.com www.example.com;      return 301 https://example.com$request_uri;  }    server {      listen 443 ssl;      server_name example.com;      root /var/www;      index index.html;                # ssl_certificate, etc...        location / {          try_files $uri $uri/ /index.html =404;      }  }  

What am I doing incorrectly here that causes the redirect loop?


Try to add ssl on; under the line listen 443 ssl; and disable disable SSLv3

server {  listen      80;  server_name example.com www.example.com;  listen 443 ssl;  ssl on;  server_name example.com;  ssl_certificate     www.example.com.crt;  ssl_certificate_key www.example.com.key;  ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;  ssl_ciphers         HIGH:!aNULL:!MD5;    location / {    rewrite     ^(.*)   https://example.com$1 permanent;  }  ...  

Or you can also use return its way faster than rewrite in niginx location blocks:

location / {    return ^(.*)   https://example.com$1 permanent;  }  

Once SSL Done You can test your ssl certificate at https://www.ssllabs.com

To create chain certificate:

 cat www.example.com.crt bundle.crt > www.example.com.chained.crt     ssl_certificate     www.example.com_chain.crt;   ssl_certificate_key www.example.com.key;  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »