Add a new domain or subdomain to your Ghost blog using NGINX and Ubuntu

When I started this blog, I forgot to configure the www. prefix. Damn it! There were so many steps to meticulously follow to get the blog going, and I was a little afraid to do anything to modify the configuration.

When I wanted to go add the new domain, there were a few steps. It took scouring around the internet, but I eventually found how.

The same general rules apply to adding new domains (e.g. if you want to change the domain name of your blog).

Step 1: Point the domain at your new IP address

Do this with your domain admin. In my case, it was in Hover. I added one line:

Step 2: Modify your NGINX configuration

I use NGINX as a web server (for Ghost).

Go to /var/etc/sites-available. You need to modify two files:

  1. your-site.com.conf (non-SSL version)
  2. your-site.com-ssl.conf (SSL version)

In both of these, you need to add in the new domain or the www. prefix into the configuration. Open up one of the files:

sudo vim /var/etc/sites-available/hooshmand.net-ssl.conf

In it you'll find the server block (it's the only thing in the file, it's right up top), where you add the www prefix (added in the image below, right after 'hooshmand.net')

Then restart nginx. TBH not sure if this is necessary, but I did it and it was painless.

sudo service nginx restart

Now add certificates for the new subdomains

sudo certbot -d hooshmand.net -d www.hooshmand.net

Note that 'certbot' is called 'letsencrypt' on some installations. It'll ask you some questions. The answers are:

  1. When it asks you something like 'There is an existing certificate. Do you want to add the new domain to the existing one?' you say 'yes'.
  2. When it asks you something like 'Do you want to redirect non-https traffic to https traffic?' also say you want to.

That's it!