Setting up a static website with nginx on Ubuntu 20. Part two.

This part is all about security. Here, you will learn how to convert your website's protocol from http to https. In order to do that, we will download some security certificates using a program called certbot. We will also get a half-decent domain name for your website since it is something certbot needs for certificate installation.

1. First, we will need to download a piece of software called certbot.

sudo add-apt-repository ppa:certbot/certbot

sudo apt-get install python-certbot-nginx

2. Next, let's get a domain name for your website.To get a free one from Compute Canada, type:

host server_public_IP_address

3. Equipped with certbot and the domain name, you are ready to get security certificates for your website.

sudo certbot --nginx -d your_domain_name

Follow the installation instructions. Choose option 2 when asked about redirection; this way, all http pages will automatically be converted to https. After you finish, you will see a whole bunch of new lines in the nginx config file. Go have a look, you have to make some adjustments to it in the next step anyway.

4. To automatically convert http pages to https, add this block to the nginx configuration file:

server{
listen 80;
server_name: externalIPadress;
return 301 https://http://yourdomainname;
}

Now, when you type your domain name in the search engine, you will automatically get an https page. Congrats! You now know how to serve a static webpage. Next, we will learn about serving dynamic webpages.