How to secure your website by enable HTTPS on Ubuntu 20.04

HTTP transfers data as plain text between the client and server, versus HTTPS encrypts data transferring between client and server. It protects data relating to financial transactions, personally identifiable information or any other sensitive data, as well as avoid having browsers flag your site as insecure.

In this guide, we’ll use Certbot to obtain a free SSL certificate from Let’s Encrypt (a Certificate Authority ) for Apache on Ubuntu 20.04, and make sure this certificate is set up to renew automatically.

Step1 Installing Cerbot

sudo apt update && sudo apt upgrade
sudo apt install certbot python3-cerbot-apache

Step 2 Verify Apache Configuration

$ cat /etc/apache2/sites-available/your_domain.conf

Make sure it match below:

...
ServerName your_domain
ServerAlias www.your_domain
...

Step 3 Make sure firewall enabled, and allow apache and ssh traffic

sudo ufw status
sudo ufw enable
sudo ufw allow 'Apache Full'
sudo ufw allow ssh

Step 4 Auto config SSL cert for Apache by Certbot apache plugin

$ sudo certbot --apache

Step 5 Verify HTTPS enabled through your browser

Step 6 Let’s Encrypt’s certificates are only valid for ninety days. The certbot script certbot.timer runs twice daily automatically renew any certificate that’s within thirty days of expiration. Lets check status of the cron job.

$ sudo systemctl status certbot.timer

Step 7 Done!

Leave a Reply