Howdy. It’s been a while since I’ve maintained the blog. So instead of upgrading everything manually I’ve just decided to rewrite everything in Terraform and migrate the data.

Create the new Droplet using Terraform

First, we need to set up the Digital Ocean Terraform provider following this guide. I added my token as an environment variable. Afterwards, we can create the droplet itself following the digital ocean droplet resource docs. I’ve published the code on GitHub if you want to have a look.

Setting up HTTPS for

After the initial setup I tried accessing but the browser complained that the certificate was invalid as it’s only valid for After some googling, I found this guide that explains how to setup ssl for additional domains.

The tl;dr is that we need to re-run the ghost config with the additonal domain so that ghost generates a new cert and a new nginx conf. Afterwards, we reset to the canonical domain and change the nginx confs of the additional domain to redirect to the canonical domain. Here’s a step by step walkthough as there are something that are not obvious:

#ssh into your droplet and swith to the ghost usr
sudo -i -u ghost-mgr

#cd into the blog directory and the run the config
cd /var/www/ghost/
ghost config url
ghost setup nginx ssl

#then reconfig to the original url and exit to the root usr
ghost config url

The next on the guide is to change the location blocks content to be return 301 [$request_uri;]($request_uri;)that is a redirect. However, this instruction is vague if you're not familiar with how nginx works. The general idea, is that the confs are kept under/etc/nginx/sites-availableand/etc/nginx/sites-enabled` , the latter being symbolic links to the former:

# ls -l  sites-*
total 24
-rw-rw-r-- 1 ghost-mgr ghost-mgr  749 Aug 11 22:16
-rw-rw-r-- 1 ghost-mgr ghost-mgr  546 Aug 11 22:15
-rw-r--r-- 1 root      root      2416 Mar 26  2020 default
-rw-rw-r-- 1 ghost-mgr ghost-mgr  553 Aug 16 21:08
-rw-rw-r-- 1 ghost-mgr ghost-mgr  337 Aug 16 21:08

total 0
lrwxrwxrwx 1 root root 46 Aug 11 22:16 -> /etc/nginx/sites-available/
lrwxrwxrwx 1 root root 42 Aug 11 22:15 -> /etc/nginx/sites-available/
lrwxrwxrwx 1 root root 50 Aug 16 20:56 -> /etc/nginx/sites-available/
lrwxrwxrwx 1 root root 46 Aug 16 20:55 -> /etc/nginx/sites-available/

So we only need to make changes under /etc/nginx/sites-available . So in our case we would modify both and by changing everything inside the first location block to redirect to the canonical domain

location / {
       return 301$request_uri;

Then test that the config is valid and reload the daemon:

nginx -t 
sudo nginx -s reload

and voila the new blog is ready to go!