In addition to this domain, I had a couple others languishing at the somewhat skeevy godaddy.com. I’d configured them to redirect to a pair of Medium publications, back when Medium was offering free SSL certificates for custom domains on their site.

I also had an obsolete Lenovo laptop running Linux, with Verizon Fios internet service, pointed to by a a DDNS name from noip.com I’d been using it for hobby-grade stuff, but the lack of HTTPS was going to be a problem.

But thanks to this article from Jeremy Gale I was able to redirect my two domains to my on-prem Ubuntu server, set up a number of subdomains, and obtain free SSL certificates for everything.

Here’s a short recap of what I did.

Domain transfer from Godaddy to Google Domains

At https://domains.google.com you can easily initiate a domain transfer. The site walks you through the process, transfers any custom DNS settings, and credits you for remaining time from godaddy.com. Cost is $12 per domain for the transfer, and $12 for renewals thereafter.

Configure DDNS

Within the DNS Settings, create a Synthetic Record of type DDNS. Don’t bother setting the IP address – that is set by this script, run from the host, that uses Google Domains API.

### Google Domains provides an API to update a DNS
### "Synthetic record". This script updates a record with 
### the script-runner's public IP address, as resolved using a DNS
### lookup.
###
### Google Dynamic DNS: https://support.google.com/domains/answer/6147083
### Synthetic Records: https://support.google.com/domains/answer/6069273

SQUAWK_USERNAME="****"
SQUAWK_PASSWORD="****"
SQUAWK_HOSTNAME="@.mistersquawk.com"

# Resolve current public IP
IP=$( dig +short myip.opendns.com @resolver1.opendns.com )
# Update Google DNS Record
URL="https://${SQUAWK_USERNAME}:${SQUAWK_PASSWORD}@domains.google.com/nic/update?hostname=${SQUAWK_HOSTNAME}&myip=${IP}"
curl -s $URL

Set up subdomains

I’m interested in a few subdomains for various projects – you can easily set those up by adding Custom resource records of type CNAME:

CNAMES

For example, after working through the Angular Tour of Heroes project, I decided to deploy it to https://heroes.mistersquawk.com.

Configure nginx server block for each domain

Because I had two domains, but only one host, I was pleased to find this post on configuring multiple domains with Nginx on Ubuntu.

The short story is you simply create a server directive block for each domain or subdomain, specifying the location of the files to serve.

server {
     listen 80;
     listen [::]:80;
     server_name domain-one.com www.domain-one.com;

     root /var/www/domain-one.com/public_html;

     index index.html index.htm;

     location / {
          try_files $uri $uri/ =404;
     }
}

Use certbot and LetsEncrypt to generate and install certificates

Certificates? That turned out to be the easiest of all. Simply head to https://certbot.eff.org/ and follow the instructions.

sudo certbot --nginx

Automatically analyzes your Nginx configuration and requests, then installs the reqired certificate. Once you’ve verified that it works

$ certbot renew --dry-run

Add this to your crontab to auto-renew the certificates:

18 4 * * * /usr/local/bin/certbot renew