0

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:

http://i.imgur.com/Z7PRD6l.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:

http://i.imgur.com/JWBEd5S.png

What's wrong? How do I fix this? Why isn't my redirect working?

0

Have you read CloudFlare's 522 connection timeout guide? Do you have SSL set to "full SSL"? For me that's within page rules, but there may be a global setting.

  • Thanks for the link. It was actually my server's firewall blocking their IPs. – user5754991 Jan 17 '16 at 23:16
  • Yeah that'll do it. – Tim Jan 17 '16 at 23:18
0

I assume you've already contacted CloudFlare's support team, right?

server {
    listen 80;
    server_name example.com;
    return 301 https://$server_name$request_uri;
}

you don't have the server_name set to serve www.example.com but in your HTTPS example you have both example.com and www.example.com

server {
    listen 443 ssl;

    root /usr/share/nginx/html/public;
    index index.php index.html index.htm;

    server_name example.com www.example.com;
...
  • Yes, I've contacted CloudFlare and am awaiting a response. I've included www.example.com in the server_name, but that hasn't solved the issue. – user5754991 Jan 17 '16 at 21:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.