I've set up Let's Encrypt (with nginx) on my server, following the tutorial I've linked in the comments. I've also set up CloudFlare with the following DNS settings:
https://i.stack.imgur.com/AV8lf.png
And my nginx configuration looks like this:
server {
listen 80;
server_name example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
root /usr/share/nginx/html/public;
index index.php index.html index.htm;
server_name example.com www.example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ^~ /.well-known/ {
allow all;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
If I go to https://www.example.com
, the site loads fine. But when I go to http://www.example.com
(not HTTPS), it shows an Error 522:
https://i.stack.imgur.com/iTJ5A.png
What's wrong? How do I fix this? Why isn't my redirect working?