Attach an external or sub domain to your zeit deployments

Hello,

Last time I talked about how to deploy your website on a CDN based platform at zeit.co.More info here:
https://iiaku.com/2019/08/06/cdn-ize-your-project-with-smart-cdn/

However when everything was done, I ended up with a deployment address looks like this: sd.iiaku.now.sh

Then I replaced all of my asset with this prefix and my assets were returned as expected. I wanted to change this to a subdomain of my main website, this is what I have done yesterday.

First you'll have to create a CNAME record into your DNS zone of your domain:

This means cdn.simply-debrid.com will point out to sd.iiaku.now.sh.

Once this was done I only added an entry zone into my nginx configuration file in order to declare this new entry, bind it to the certs.

NB: I am using let'sencrypt for SSL management, basically certificates are initialy design for the main domain. Recently let'sencrypt added wilcard support meaning they will handle SSL for your main domain and subdomain *.youdomain.com.

So I just changed my certificates to a wildcard one:

/usr/bin/certbot certonly --manual  --email YOUR_EMAIL_ADDRESS --server https://acme-v02.api.letsencrypt.org/directory --agree-tos -d *.YOUR_DOMAIN

You'll be asked to confirm challenge while adding a TXT RECORD for:

TXT acme-challenge.YOUR_DOMAIN with value from cli

Once the certs are ok, update your nginx accordingly.
/etc/nginx/site-enabled/default

Once this is done make sure you have now-cli installed, if not:

npm install -g now

Then to alias your subdomain the command is:

now alias https://YOUR_DOMAIN.now.sh you.subdomain

Creating an alias

You'll have to make a TXT RECORD to confirm you own the domain.

Zeit will generate SSL for you an alias your domain to their url, then you'll be able to get your asset hosted on zeit.co but from your subdomain.

More info here:

Enjoy,