Setup HTTPS on your website for free

Curious software engineer
Search for a command to run...

Curious software engineer
In this series, I will treat subjects related to software development, software engineering, and related career.
One of my resolution for this year is to keep improving my leadership and management practices. And the first thing I am going to set is my clear contract. If you are not familiar with the term, check the article from the great Fred de Villamil: http...
It’s the summer holidays, after all. So I wanted to spent some time with my 7 years old daughter to teach her programming. ⌨️ I spent some time before discussing with her some of the basics concept verbally: the different parts of a computer, and bas...

This article is a follow up on my previous one introducing the concept of SE Spectrum: https://sonny.alvesdi.as/a-better-way-to-discuss Existing solutions For long, the easiest way to run a spectrum was to use visual drawing or diagram tools like ...

Introduction to SE Spectrum

One of the greatest tool available on GitHub is Dependabot. For those not familiar with it, in short it's a bot reviewing your list of dependencies and proposing PRs to update them. https://docs.github.com/en/code-security/getting-started/dependabot-...

Photo by Harli Marten on Unsplash As long as I remember I have always been interested by skepticism. And I think one element that really resonated with me has been that conference talk by Phil Plait: https://www.youtube.com/watch?v=FrFRbGjUtJk 15 ...

There was a time when SSL certificates were expensive. Now with Let's Encrypt and Certbot, you can have SSL certificates for free valid for three months renewable. And those certificates are necessary for you to enable HTTPS communication on your website.
A couple of points on why you need HTTPS:
Security By using HTTP, communication is not encrypted. For example, when one authenticates and sends his credentials to your server, the information will be transmitted in clear. Hence, a hacker could potentially capture communication and read your visitor's password.
SEO Google and other search engines nowadays list, in priority, the HTTPS websites. If you only serve HTTP on your website will be at the bottom of the list.
Image Do not underestimate it, but now most people are aware of security measures on the web. HTTPS is one of the most important measures to secure a website that also improves your credibility.
Fortunately, this is pretty easy nowadays, there are a couple of solutions to generate an SSL certificate for your website like ZeroSSL, but as I mentioned, we are going to use Certbot.
Certbot can generate certificates recognized by all modern browsers. It generates certificates with three months validity maximum, but you can renew for three months as long as you want. They also offer wildcard certificates, which I will not explain here (but in a future article).
Here is an example of how to use Certbot if you are using Nginx on Ubuntu 16.04.
First, once Nginx has been installed, define a simple configuration like:
server {
server_name yourdomain.com;
listen 80;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
}
Then to install Certbot, use the following instructions:
sudo apt-get update
sudo apt-get install certbot python-certbot-nginx
Finally, just run:
sudo certbot --nginx
Certbot will automatically detect your domain (defined in server_name) and propose to generate an SSL for it. During the process, it will ask whether you want to force redirection from HTTP to HTTPS, I strongly recommend activating it.
Et voilà, your website is protected for the next three months.
The final touch, to automate the renewal of your certificate, schedule a cronjob. Add the following lines to your cron as a superuser (sudo crontab -e).
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin:/root/bin
0 16 * * * certbot renew
0 4 * * * certbot renew
Here we are doing the verification twice every day to make sure the certificate will be renewed without any issue on the expiration day.