Before going to the tutorial, lets take a brief look at HTTP and HTTPS. HTTPS stands for HyperText Transfer Protocol Secure which is also referred to as HTTP over TLS or HTTP over SSL. Most websites today use HTTPS not HTTP. So, What is the difference?
The difference can be explained using the above figure.
HTTP transfers data between the browser and the web server in the hypertext format, in other words, hackers can see what you are receiving and sending between the browser and the server.
To solve these issues, HTTPS was introduced. HTTPS encrypts all the data before transferring. Hackers can not read or modify the data during the transfer between the web server and the browser. Even if they managed to intercept the communication, no one can read the encrypted data.
HTTPS uses the TLS protocol (Transport Layer Security) to encrypt communications. TLS is also known as SSL (Secure Socket Layer).The type of security method uses by the SSL is asymmetric public-key encryption that uses two different keys to encrypt and decrypt the data communication between the two parties.
The private key - stored on a web server (controlled by the owner) and this is private. This key is used to decrypt information encrypted by the public key.
The public key - Available to everyone who wants to communicate with the server. Data that is encrypted by the public key can only be decrypted by the private key.
I think now you have some basic knowledge about the differences between the HTTP and HTTPS. Let's move on to the practical part. Before that, you should be aware that there are many other ways to create an HTTPS server without using certbot application and Azure cloud platform.
The whole process can be broken down into 4 steps.
- Create a Microsoft Account
- Build a new virtual machine on Azure cloud platform.
- Connect to the VM via SSH and configure it.
- Test the connection with ssllabs.
- First thing we need to do is signing into the Microsft Azure account. Even though they don't charge you, you have to enter credit card details when creating the account.
If you are a university student, you may get the Microsft Azure student offer. All you have to do is providing your university email. No need to enter credit card details.
- After creating the account sign in to it and go to the Azure Portal. This dashboard allows you to manage each cloud service which Microsft provides.
On the Basic tab, you need to set a name for your VM, select the region you need. Select which OS you are willing to run on the VM. I am using Ubuntu Server 16 LTS. Then select machine size and SSH as the authentication type.
Leave all the setting as they are on other tabs such as Disks, Networking, Advanced, etc unless you don't know much about them. For this tutorial, these Basic setting are enough.
By default the VM doesn't have a DNS name. To create a new DNS we have to stop the VM for a little. Click Stop button to stop the VM. Azure will ask whether to reserve the Public IP address or not. Check the box and click OK.
Now click configure link next do DNS name. Select the Static DNS assignment option. Type a DNS name label. A green check icon will appear if the given name is valid. Then save the configuration. Go back to VM dashboard and Start the VM.
Now you have a working VM. If we visit the IP or the DNS now the browser will show an error saying the site can't be reached.
The first thing you need to do is connecting to the VM using SSH protocol. If you are on Linux, you can just do it on the terminal. But if you are on Windows, you have to download an SSH client software like putty. Download and install it on windows. Putty settings for SSHing into a server may vary a bit. But I am sure you can manage it. It is not a big deal.
From now on you will have to run commands in both the VM and your host machine. To avoid running those commands in the wrong machine I will label each of the commands.
(VM) <command 1> - Run this on your VM's terminal.
(host) <command 2> - Run on your machine.
Now connect to the VM in your terminal. On Linux, use the below command.
-idenotes for identity file. You should give the path to the downloaded private key file.
(host) sudo ssh -i httpsVM_key.pem email@example.com
After remote login in, update the system repositories.
(VM) sudo apt-get update
As the next step we will install apache2.
(VM) sudo apt-get install apache2
Delete default apache2 index page. /var/www/html directory contains the files of the website.
(VM) sudo rm /var/www/html/index.html
Now copy your website's index.html to /var/www/html directory. How do we copy a file from our host PC to our VM? We use SCP (secure copy) command. Open a new terminal and run these commands.
(host) sudo scp -i ~/Downloads/httpsVM_key.pem index.html firstname.lastname@example.org:/home/azureuser
Then copy the file to the HTML directory.
(VM) sudo cp index.html /var/www/html
Check the result by visiting the IP address again.
Add certbot repository and install it using these commands.
(VM) sudo add-apt-repository universe
(VM) sudo add-apt-repository ppa:certbot/certbot
(VM) sudo apt-get install python-certbot-apache
Now obtain the SSL certificate from letsEncrypt server by running this command. Make sure your DNS name is given correctly.
(VM) sudo certbot --apache -d tenet.eastus.cloudapp.azure.com
It will ask few details step by step. Enter an email for security notices. Agree to the Terms and conditions.
When it asks, "Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access", select 2:Redirect option by entering 2.
- Congratulations, now you have an HTTPS server! Now let's test our SSL server.
- Paste the domain name of your web server. It may take few minutes to get the result.
Your certificate and chain is stored at:
Your SSL configuration file is:
[Important!] After you finish this tutorial stop the VM. Otherwise, you will waste your free credits for the platform.
There are other easy peasy ways of doing this job. But I hope you got a good idea about how to create an HTTPS server on Azure cloud. Stay safe!
"Why do we fall? So we can learn to pick ourselves back up." ~ Crhistoper Nolan