The domain willson.ga expired, now I am switching to willson.tk from Freenom for 1 year.

It is necessary to set up the proper nameservers when registering the domain name with freenom. I use cloudflare (free) for DNS nameservers. I used the following (provided by cloudflare):

austin.ns.cloudflare.com
bonnie.ns.cloudflare.com

Run a dig query on the domain name to verify that the DNS entry is configured properly.

Verify correct nameservers

$ dig ns willson.tk

Verify correct A record

$ dig willson.tk

Configure the servers to accept connections for willson.tk

Edit the /etc/nginx/sites-available/default file and add entries for willson.tk

server {
	listen 80 default_server;
	listen [::]:80 default_server;
	server_name willson.ga www.willson.ga;
	server_name willson.tk www.willson.tk;
	return 302 https://$server_name$request_uri;
}

Add a server entry for willson.tk and www.willson.tk

Create a new file under /etc/nginx/sites-available/ for the willson.tk domain name.

Use the following nginx commands to test the configuration

Verify that the configuration files have correct syntax

$ nginx -t

Reload the configuration files without restarting nginx

$ nginx -s reload

Request the page, and watch what happens

$ wget willson.tk

Verify that willson.tk can be reached.

Generate a certificate to configure encryption

Download certbot and use the following command to test whether you can generate a certificate

I set up a file in /etc/nginx/sites-available and created a symlink to that file in /etc/nginx/sites-enabled

The contents of the file:

server {
        listen 80 default_server;
        listen [::]:80 default_server;
        server_name willson.tk www.willson.tk;
        location /notes/ {
               root /var/www/html;
               index index.html;
               autoindex on;
        }
        location / {
               try_files $uri $uri/ =404;
               root /var/www/html;
               index index.html index.htm index.nginx-debian.html;
       }
}

Verify that certbot will work when generating a new certificate

$ sudo certbot certonly --webroot -w /var/www/html -d willson.tk -d www.willson.tk --dry-run

If the test works, generate the certificates!

$ sudo certbot certonly --webroot -w /var/www/html -d willson.tk -d www.willson.tk

This will save the certificates to:

   /etc/letsencrypt/live/willson.tk/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/willson.tk/privkey.pem

Configure nginx to use those certificates in the sites-available file

Example /etc/nginx/sites-available/willson.tk file below (symlinked to /etc/nginx/sites-enabled/willson.tk):

server {
        listen 80 default_server;
        listen [::]:80 default_server;
        server_name willson.tk www.willson.tk;
        return 302 https://$server_name$request_uri;
}

# FOR THE WILLSON.TK domain
server {
        server_name willson.tk www.willson.tk;
        listen 443 ssl; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/willson.tk/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/willson.tk/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/ssl/certs/dhparam.pem;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
                root /var/www/html;
                # Add index.php to the list if you are using PHP
                index index.html index.htm index.nginx-debian.html;
        }

     #Redirect non-https traffic to https
        if ($scheme != "https") {
                return 301 https://$host$request_uri;
        } # managed by Certbot
}