Ghost CMS makes it fairly easy to link your blog to your own domain and set up SSL. The ghost setup
command in ghost-cli basically does it for you. However, for me it didn’t automatically set up a www subdomain. So I could access, say, https://myblog.lol
, but https://www.myblog.lol
would result in a 502
. I was thinking of just adding a CNAME or ALIAS record in my provider’s DNS settings, but that didn’t work somehow. So I just set an A record to point from www to the IP of my Ghost blog, which worked fine, but I didn’t have any SSL then on my www subdomain. Thus, I had to tinker a bit in the nginx configs of Ghost, so that it automatically redirects all www traffic to the apex. I think that that’s a pretty safe solution.
First, I would configure the www url by cd
ing into /var/www/ghost
and run ghost config url https://www.myblog.lol
.
Then configure ssl via ghost setup nginx ssl
. Set my config again to the apex domain with ghost config url https://myblog.lol
. And now you will have to edit the nginx configs in /etc/nginx/sites-available
. Go there, and if there are no files called www.myblog.lol-ssl.conf
and www.myblog.lol.conf
create them. The first one will have to look like this:
The latter one should be this:
That’s it. Run sudo nginx -t
to make sure you don’t have any typo in your config files and then source your config files with sudo nginx -s reload
. You might have to do ghost restart
, if your www subdomain does not work immediately.