Overview

In this guide, I will show you how to get free ssl or https for your django site.

We will be using Certbot, which will automatically deploy Let's Encrypt certificates.

Prerequisites

This article assumes that you already have your django project setup with nginx and gunicorn.

If not, you can check out the tutorial on How to setup django, nginx and gunicorn.

Let's Start

This is tested on Ubuntu 16.04(xenial) and should also work on later versions of ubuntu.

FIrst run these commands to install the required packages.

sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository universe
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install certbot python-certbot-nginx 

After installing all the above packages,run the command below to activate https :

sudo certbot --nginx

Here, you will be asked to enter the names of your site you want to activate https for, something like this:

Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: raturi.in
2: www.raturi.in

Enter the corresponding number with comma(,) to seperate more than one domain.

After that fill the details it asks and proceed.

This will setup https for you.

Finally, run:

sudo service nginx restart

Now, visit your domain, you can check https there.

Automating renewal

The Certbot packages on your system come with a cron job that will renew your certificates automatically before they expire. Since Let's Encrypt certificates last for 90 days, it's highly advisable to take advantage of this feature. You can test automatic renewal for your certificates by running this command:

sudo certbot renew --dry-run