Trouble with ghost, nginx and ssl

May 29, 2014 2.6k views
I am having epic troubles with getting ssl on my droplet with ghost, nginx. I created a droplet with ghost pre installed. It worked great. Then I grabbed a startssl certificate and followed the general instructions for install ssl on nginx Now when I access http://blog.samjohnduke.com i get correctly redirected to https version. But nothing happens and after a minute or so it times out. my nginx default.conf file is server { listen 80; listen 443 default ssl; server_name blog.samjohnduke.com; ssl_certificate /etc/nginx/ssl/blog.samjohnduke.com.chain.pem; ssl_certificate_key /etc/nginx/ssl/blog.samjohnduke.com.key; add_header Strict-Transport-Security max-age=31536000; add_header X-Frame-Options DENY; client_max_body_size 10M; location / { proxy_pass http://localhost:2368/; proxy_set_header Host $host; proxy_buffering off; } } Thanks, Sam
2 Answers
Answering my own question because I fixed it and people should know.

I changed listen 443 default ssl; to listen 443;

I added ssl on; just before the ssl_certificate directive

I added
proxy_set_header X-Forwarded-Proto https;
just after proxy_pass in the location directive.

this allowed me to have ssl enabled by default on every page. YAY!

Hi Sam,

I've just set up something similar to you, just thought I'd point out that you may run into issues with users hitting port 80 and getting errors because you've Strict-Transport-Security enabled.

Something like this might be a better option, redirecting all users from port 80 HTTP to port 443 HTTPS:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    server_name www.example.com example.com;

    return 301 https://$server_name$request_uri;
}
server {
    listen 443 ssl;
    listen [::]:443 ipv6only=on;
    server_name www.example.com example.com;

    access_log   /var/log/nginx/www.example.com.access.log;
    error_log    /var/log/nginx/www.example.com.error.log;

    ssl_certificate /etc/nginx/ssl/www.example.com.chain.pem;
    ssl_certificate_key /etc/nginx/ssl/www.example.com.key;

    add_header Strict-Transport-Security max-age=31536000;
    add_header X-Frame-Options DENY;

    location / {
        proxy_pass http://localhost:2368;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_buffering off;
    }
}

This will make sure all requests are 100% SSL 100% of the time :)

Have another answer? Share your knowledge.