How to change the website hosted on AWS from http to https protocol?(Django website hosted on AWS ec2)
By: Sarath Kumar R S
Tags: Free Ssl Certificate, Filezilla, Django, Httpscertificate, AWS

HTTPS is a must for every website nowadays: Users are looking for the padlock when providing their details; Chrome and Firefox explicitly mark websites that provide forms on pages without HTTPS as being non-secure; it is an SEO ranking factor; and it has a serious impact on privacy in general.

In this guide, I will explain the individual components and steps and will clearly cover the individual stages of the setup.

We will be getting certificate from a free ssl provider webiste which is sslforfree.com and we will be implementing it on a Django webiste. So the steps provided will be more inclined to Django websites and web applications.

We will jump into pratical implementation after we get our basics right.

The Hyper Text Transfer Protocol(HTTP) is the basic communication protocol that both client and servers must implement in order to be able to communicate. It covers things such as requests and responses, sessions, caching, authentication and more.

The protocol transfers information between the browser and the server in clear text, allowing the network, through which the information passes, to see the information transmitted. This is the concern, So HTTP Secure(HTTPS) was introduced, allowing the client and server to first establish an encripted communication channel, and then pass the clear text HTTP messages through it, effectively protecting them from intruders.

The encrypted channel is created using the Transport Layer Security(TLS) protocol, previously called Secure Socket Layer(SSL). The terms SSL and TLS are often used interchangeably.

I think more theory may exhaust you, so let’s see how it is done.

Step by step

Go to sslforfree.com and create an account. Create a new certificate

3. Enter the domain you want to encrypt and click Next Step.

4. You can see 3 options, in this article I will be choosing the third method ie. HTTP file upload.

5. When selected they will ask us to download the auth file and put that into some url. Download the auth file and store it on our system.

6. We will get a .txt file, Go to the Django project and put that inside our template folder where we place our site files or in the same folder of index.html

7. Then inside your main app(your project main app), go to views.py and create a new view. Example shown below.

def free_ssl(request): context ={ “title”: “Best Career”, “caption”: “Home”, } return render(request, “web/81F92FC39FA6C5237F886CFFA8AC5BDF.txt”, context)

8. Then go to urls.py, main urls.py which is with settings.py

from main import views urlpatterns=[ …… path(‘.well-known/pki-validation/81F92FC39FA6C5237F886CFFA8AC5BDF.txt’, views.free_ssl, name=’free_ssl’) ……… ]

9. Then after click next step and click verify domain

10. If you have done everything until now correctly the domain will be verified and the certificate will be issued.

11. Click install and Downlad the zip folder containing certificates.

12. Now you need to connect the server with a file transfer protocol. I am using Filezilla for this purpose and my website is hosted on AWS.

I have seperate article for connecting filezilla to ec2

13. Extract the file we downloaded from Freessl and upload the certificate to a folder in the server, am uploading the certificates to /etc/ssl/bestcareer.org.in

14. Then you go to your apache2 config file and configure the certificate there.

15. Edit your site config file, here my config file is 000-defaul.conf

<VirtualHost *:80>

ServerName www.bestcareer.org.in

ServerAlias bestcareer.org.in

Redirect permanent / https://bestcareer.org.in/

</VirtualHost> <VirtualHost *:443> ……. SSLEngine on

SSLCertificateFile /etc/ssl/bestcareer.org.in/certificate.crt

SSLCertificateKeyFile /etc/ssl/bestcareer.org.in/private.key

SSLCACertificateFile /etc/ssl/bestcareer.org.in/ca_bundle.crt </VirtualHost>

16. Also run the command to enable the ssl module in the server

sudo a2enmod ssl

17. check wheather the system configuration is correct by using the command.

sudo apache2ctl configtest

18. If the server is configured right, it will return a syntax OK

19. Then restart the server

sudo service apache2 restart

20. Now reload the site and see that the site protocol is changed form http to https.

Cheers!!!

Sarath Kumar R S

Efuturex Technologies