# Deploy a Simple web application in EC2 using NGINX and certify using Certbot

**Setup a barebone Ubuntu Server in AWS**

Requirements:

1. Must use a imported ssh key (Use ed25519 key)(done)
    
2. should have a elastic IP attached (done)
    
3. Must allow ssh key pair
    

Setup a Webserver

Domain to use: custom domain name(if you have)

Must have SSL/TLS enabled (Use certbot for this) [Certbot](https://certbot.eff.org/)

[https://certbot.eff.org/favicon.ico](https://certbot.eff.org/favicon.ico)

Must use NGINX as a webserver (done)

References:

[How To Generate ed25519 SSH Key](https://www.unixtutorial.org/how-to-generate-ed25519-ssh-key/)

[https://www.unixtutorial.org/favicon.ico](https://www.unixtutorial.org/favicon.ico)

---

1. **Generating ssh key in ubuntu server**
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1708133823593/2c0f2955-1c89-4751-9ce9-b5de1ed29f51.png align="center")
    
2. **Importing ssh key**
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1708134025351/85d48444-5508-4c43-aad1-9e5bac9c6acd.png align="center")
    
3. **Deleting the Existing ssh key and updating with the self generated key pair (imported) using VIM editor**`.ssh/authorized_keys` file on the ubuntu instance.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1708134137045/427746f1-5a82-439e-b61b-4c427d0b924a.png align="center")
    

*passphrase: mercantilesshpassphrase*

1. **Adding additional ssh key pair**
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1708134169032/cc154140-be4b-4e53-84c1-168206dd4ea3.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1708134186467/71ea3461-2267-4180-9fbe-840b325221fa.png align="center")
    
2. **Attaching Elastic IP**
    

**Elastic IP**

An *Elastic IP address* is a static IPv4 address designed for dynamic cloud computing. An Elastic IP address is allocated to your AWS account, and is yours until you release it. By using an Elastic IP address, you can mask the failure of an instance or software by rapidly remapping the address to another instance in your account. Alternatively, you can specify the Elastic IP address in a DNS record for your domain, so that your domain points to your instance. For more information, see the documentation for your domain registrar, or [Set up dynamic DNS on your Amazon Linux instance](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/dynamic-dns.html).

An Elastic IP address is a public IPv4 address, which is reachable from the internet. If your instance does not have a public IPv4 address, you can associate an Elastic IP address with your instance to enable communication with the internet. For example, this allows you to connect to your instance from your local computer.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1708134257674/44f0125c-d1c2-42d0-9eb4-085937aee07e.png align="right")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1708134269465/335230a0-60cb-44f1-b97b-ad52dd663bc9.png align="center")

*Elastic IP: 13.200.34.252*

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1708134297423/7bc6cf0c-1383-4d1d-8cd3-d5b4a48d2e7e.png align="center")

1. **Installing Certbot**
    

```jsx
sudo apt-get install certbot python3-certbot-nginx
```

1. **Route S3 for personal Domain**
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1708183381305/0122be72-7a84-4e65-aa88-f7ffe425b4fb.png align="center")
    

Creating a custom record in route 53 for domain

[www.lajahmercantile.test.mercantilecloud.com.np](http://www.lajahmercantile.test.mercantilecloud.com.np/)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1708183395750/68306aa2-190c-46c0-9077-c1a9cda57725.png align="center")

Route53 successfully redirecting to the instance that is hosting webpage using Nginx server

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1708183411788/51ab2a7a-f3c7-42e5-b6bf-545b1cf14fbf.png align="center")

1. **Managing Website Files**
    

Cloning the static website example into the instance working repository

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1708183703194/94182ee9-f848-4e2d-b35e-352bf890b21c.png align="center")

Copying the website files to the `/var/www/lajahmercantile@mercantilecloud.com.np` directory

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1708183715900/0eff9d73-2888-48dd-a8a0-76054df63e44.png align="center")

1. **Configuring NGINX to serve my static website:**
    

→Modifying the default configuration file `/etc/nginx/sites-enable/default` for the server to locate our custom website

```jsx
sudo vim default
```

→ changing the default root location to the location containing out sample html file.

1. ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1708183732085/431b0ade-7fc9-4041-91f1-062842913f34.png align="center")
    
    **Restarting Nginx**
    

```jsx
sudo systemctl restart restart nginx
```

1. **Verifying the changes**
    

Sample website Sucessfully hosted on nginx server sunning on Ubuntu webserver on custom domain created via Route 53

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1708183739596/30f0f19b-08ee-4c02-a2df-086b15392f5a.png align="center")
