vendredi 9 octobre 2015

Nginx Redirect HTTP to HTTPS and WWW to Non-WWW

I'm having issues with this config:

#=========================#
# carsonevans.ca settings #
#=========================#

# Catch http://carsonevans.ca, and http://ift.tt/1LmBkdK
server {
        listen 80;
        server_name www.carsonevans.ca carsonevans.ca;

        # Redirect to https://carsonevans.ca
        return 301 http://ift.tt/1MiRIrZ;
}

# Catch http://ift.tt/1LmBkdM
server {
        listen 443;
        server_name www.carsonevans.ca;

        # Redirect to https://carsonevans.ca
        return 301 http://ift.tt/1MiRIrZ;
}

# Catch https://carsonevans.ca
server {
        listen 443;
        server_name carsonevans.ca;

        root /usr/share/nginx/carsonevans.ca;
        index index.html index.htm;

        ssl on;
        ssl_certificate /etc/nginx/ssl/server.crt;
        ssl_certificate_key /etc/nginx/ssl/server.key;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
        ssl_prefer_server_ciphers on;

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

Something is wrong with the 3rd server directive. I get a SSL connection error. But when I comment our that section everything works fine. But I want www to redirect to non-www over https also

Can anyone spot the problem?




Aucun commentaire:

Enregistrer un commentaire