mercredi 3 janvier 2018

Nginx with SSL and forcing www usage config throws too many redirects

I configured a ssl with cerbot and nginx. and I'm trying to force the use of https plus www

I have this config in my other site and works perfectly, but in this new site throws me an error in browser, TOO MANY REDIRECTS.

How I think it should we is, example.com in ports 443 and 80 will redirect to www.example.com at 433 www.example.com port 80 will redirect to www.example.com at 433

And agian, the same config WORKS with another domain, I don't know why

server {
  listen 80;
  listen [::]:80;
  server_name example.com;

  listen 443 ssl; # managed by Certbot
  ssl_certificate /etc/letsencrypt/live/http://ift.tt/1OCiVLJ; # managed by Certbot
  ssl_certificate_key /etc/letsencrypt/live/http://ift.tt/1LSjYB2; # managed by Certbot
  include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
  ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

  return 301 http://ift.tt/V2T1rx;
}

server {
  listen 80;
  listen [::]:80;
  listen 443 ssl; # managed by Certbot

  root /var/www/example.com/html;

  index index.html index.htm index.nginx-debian.html;

  server_name www.example.com;

  location / {
    try_files $uri $uri/ =404;
  }

  ssl_certificate /etc/letsencrypt/live/http://ift.tt/1OCiVLJ; # managed by Certbot
  ssl_certificate_key /etc/letsencrypt/live/http://ift.tt/1LSjYB2; # managed by Certbot
  include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
  ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

  if ($scheme != "https") {
    return 301 https://$host$request_uri;
    } # managed by Certbot
}




Aucun commentaire:

Enregistrer un commentaire