1

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?

1

3 Answers 3

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.

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

check your Inbound firewall rules for ec2 - make sure port 80 / 443 are exposed.

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;
...
1
  • 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.
    – j1834982
    Jan 17, 2016 at 21:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .