now alias command allows you to alias any now.sh deployment to one of your custom domain names. For example, when I aliased this Ghost deployment to my n8.io domain name, I ran:
$ now alias set ghost-krjpyhytqq.now.sh n8.io > n8.io is a custom domain. > Verifying the DNS settings for n8.io (see https://zeit.world for help) > Verification OK! > Success! Alias created (ABCCAwOwoYnMdt0A2APPUXyZ): https://n8.io now points to https://ghost-krjpyhytqq.now.sh (aBCMRT3LQqqS4X33QMYDJxyz)
In order for this to work, you must configure your domain's DNS records to point to the zeit.world nameservers.
The problem was that I was using Google Domains for DNS management to leverage dynamic DNS records and Google Apps MX records, so I couldn't simply point the
NS record and call it a day.
I wanted my root domain name (n8.io) to resolve to the zeit.world servers so that
now alias would work as expected, but retain other records like my
MX mail record and my wildcard
CNAME record resolving to the root domain (so that foo.n8.io will resolve to n8.io, which ultimately will resolve to the Zeit servers).
Some DNS providers support what's called an
ALIAS DNS record, which is like a top-level
A record that can point to a hostname address that can be dynamically updated (similar to a
CNAME record for subdomains).
If your DNS provider supports
ALIAS records, then simply create one and point it to "alias.zeit.co" and you're done!
Google, however, does not support this record type…
Fortunately they do support what's called "Dynamic DNS", which in short means that you can programmatically update the IP address that this particular dynamic DNS record points to.
In the Google Domains "Configure DNS" area, add a new "Dynamic DNS" record pointing to the root of the domain name. To do this, specify an
@ character as the name of the record. Then hit the "Add" button to create the new record.
Expand the dropdown on your new synthetic record and find the "View Credentials" link. Click on it and copy down the username and password that were generated on your behalf. These credentials will be used in just a moment.
Now we need a script that will update this dynamic DNS record to point to the
alias.zeit.co domain name on a periodic interval (typical
ALIAS records update every 5 minutes). I've written such a script:
See the usage instructions inside the script. You need to specify the
TARGET as env variables for the script to operate properly. Invoking the script a single time will attempt to update the Dynamic DNS record to match what
TARGET is resolving to.
*/5 * * * * USERNAME=___ PASSWORD=___ HOST=___ TARGET=___ /path/to/update.sh
Fill in the blanks, and we're done!
At this point your dynamic DNS record (
HOST) will be updated to point to the
TARGET domain name every 5 minutes. Yay automation!