Host a website on Azure Virtual Machine with SSL enabled using Let's Encrypt & add a custom domain managed by Azure DNS.
Tags: azure, aws, github
Published: 2022-08-02 17:36:00


## Create a Virtual machine and install a web server

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b1gyoevso52jc16x9o1v.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hu143rgskdqhyoljbc0x.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9rhhdcf63xdeydoz8dlm.png)

**Now connect this servers with xshell.**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4dtbpp0abmlwl68bn8cb.png)

**Here we are going to install apache server**

```
apt install apache2
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n5q35trn9nyrk973rznb.png)

**We can use Github commands to clone our website code from our repo ,so You need to install git.**

```
apt install git -y
```
**we have to clone that repo to our web server folder name [ html ] as follow**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xgjdjp0n5bwsjdtzpo2n.png)

**[In case if we stop and start our server , we need start our apache again , to avoid this we can simply enable that server]**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/codlihm1h5qm9aeqrgx9.png)

**Now paste the public ip in the browser and you will see your website.[Not fully secure]**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6nymosbv9ytvg11lcdov.png)

## How to attach a domain name

**you require a free or purchased domain to fully complete all the steps. If you already have a domain, then awesome, if not, don't worry, you can get a free domain! You can visit the following site and get yourself a free domain.** 

```
https://www.freenom.com/en/index.html?lang=en

```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5o2ul6fbjddx2vvf7vau.png)

**Once you sort out your domain, you should go back to the Azure console and navigate to the AZURE DNS service.**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gb0ez4h90s2dmtosnvwo.png)

## Create a DNS zone

**Azure DNS is a hosting service for DNS domains that provides name resolution by using Microsoft Azure infrastructure.**
**By hosting your domains in Azure, you can manage your DNS records by using the same credentials, APIs, tools, and billing as your other Azure.**

**You have to make sure to enter the exact domain name as shown below**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5h9dtb8b9l5plid9s5hm.png)

**After that put this name server inside your domain name server [freenom]**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bsuvnk412lhxhsybmm4r.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/90l624dfvvs6ww2wxyev.png)

**You can alse add a record set as shown below.**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9ow8nk65dtu2i8400gth.png)

**Now our domain is fully binds with our public ip.**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o759f2wr7zefrs1ylhe6.png)

**But its not Secure**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zrj6fnm23fomy6vurtk9.png)

## How To Secure Apache with Let's Encrypt on Ubuntu.

**Let’s Encrypt is a Certificate Authority (CA) that gives a simple method to acquire and introduce free TLS/SSL declarations, along these lines empowering encoded HTTPS on web servers.** 
**It rearranges the procedure by giving a product customer, Certbot, that endeavors to mechanize most (if not the entirety) of the necessary advances.** 

**Step 1: Update  System**

```
sudo apt-get update 
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tr05nk8yv9ie19skz2ys.png)

**Step 2: Install Certbot**

```
sudo certbot --apache -d cloud167.ml -d www.cloud167.ml
```
Its auto verify the domain and its will create all required files to configure in virtualhost ssl parameter, After installation and configuration, You will get the successful message, Now you can access with yours domain like this.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/haiea6z9avugxhsqy46n.png)

**Type 2**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dbu7c4517a9pmws64dyd.png)

**Here we have successfully installed and configure lets encrypt valid certificate with apache web server**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8u5otbf52glvvytmut32.png)

**Paste your domain name in browser as shown below its fully secured now**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wdwrrkd904n0dufmtxda.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/byfo172lc98yn9m7ocbw.png)