DEV Community

Cover image for HOSTING A FUNCTIONAL WEB APP ON VIRTUAL MACHINE
Oluwaseun Olaleye
Oluwaseun Olaleye

Posted on

HOSTING A FUNCTIONAL WEB APP ON VIRTUAL MACHINE

USE CASE
I was tasked with deploying an application to a live server, ensuring high availability, scalability, and monitoring the application performance.

Image description

PREREQUISITES

  • Basic Linux Commands

  • Ubuntu Server

  • Custom Domain.

  • Basic Networking.

DEFINITION OF SERVICES

  1. Virtual Private Cloud: This is a virtual networking environment where you can launch AWS resources.

  2. Elastic Compute Cloud: It is a virtual machine that provides resizable compute capacity in the cloud.

  3. Elastic Block Store: It is a block-level storage service that provides persistent storage for EC2 instances.

  4. EBS Snapshot: It is a point-in-time copy of an EBS volume.

  5. AWS CloudWatch: This provide data and insights about AWS resources and applications.

  6. Auto Scaling Group: This automatically adjust the number of instances in the group based on changing workload demands, ensuring that your application has the necessary resources to handle increased traffic or demand.

VIRTUAL PRIVATE CLOUD (VPC)
Let's start with the networking aspect of our application. In AWS, we utilize a Virtual Private Cloud (VPC) to secure our infrastructure. Since cloud computing relies on shared public infrastructure, a VPC provides a secure, isolated environment for our application. This enables us to control incoming and outgoing traffic, ensuring the security and integrity of our website.

Image description

Image description

Image description

Image description

ELASTIC COMPUTE CLOUD

Next, we'll create an Amazon EC2 instance to host our application. On this instance, we'll install Nginx, a popular web server, and configure it to listen on port 80 (the default HTTP port). This will enable our application to serve web content to users.

Image description

Next, create a new key pair and utilize the custom VPC previously created. Ensure public IP assignment is enabled.

Image description

Image description

Next, update the security group created earlier by adding HTTP (port 80) and HTTPS (port 443) inbound rules. This will enable internet access to the web server.

Image description

Image description

Next, connect to the instance and Update the package list as well as installing Nginx web server software.

Image description

Image description

Image description

Image description

Next, enable the firewall to allow inbound traffic on port 80 (HTTP) to permit external access to the web server.

Image description

Next, download the HTML files and create a new directory at /var/www to host the website files.

Image description

Next, navigate to the /etc/nginx directory and create a symbolic link to the HTML files in the sites-available and sites-enabled directories.

Image description

Next, navigate to the /etc/nginx directory and create a symbolic link to the HTML files in the sites-available and sites-enabled directories.

Image description

Image description

"Next, remove the default Nginx page, as it is no longer needed since we have uploaded our customized HTML files.

Image description

Image description

Image description

Next is to update our DNS manager with the IP address of the instance. Kindly go to your domain provider and update the DNS Manager.

Image description
Next is to access the web app using the domain name instead of the IP address.

Image description

Next, let's install Certbot to secure the web application.

Image description

Image description

Image description

With the Certbot certificate in place, our web application now has an additional layer of security, safeguarding user information and preventing potential threats.

Image description

Elastic Block Store
Next, we will add additional storage to our instance to accommodate surges in traffic on our web application. We will create an EBS volume and attach it to the instance that was created. Firstly, let's check our default EBS Volume attached to our EC2 instance.

Image description

Image description

Image description

Let's leave everything in default and create our EBS volume. Next, let's attach the volume to the instance.

Image description

Image description

Image description

Image description

Image description

Image description

EBS SNAPSHOT
Let's create EBS snapshot, this will serve as a backup for the EBS volume.

Image description

Now, let's create another EC2 instance and attached it to the snapshot and connect via ssh.
Next, let's navigate to EBS Volume and create the snapshot.

Image description

Image description

Image description

Image description

Image description

Image description

Image description

Image description

Image description

AWS CLOUDWATCH
Now that the web application is secured, the next step is to set up CloudWatch to monitor its performance and trigger alarms when necessary. This will help us monitor Memory and Disk. Firstly, let's configure CloudWatch agent.

Image description

Image description

Next, let's create IAM role for the CloudWatch agent.

Image description

Image description

Image description

Now let attached the role created to the instance.

Image description

Image description

Image description

Next is to continue with the configuration for the CloudWatch.

Image description

Image description

Image description

Image description

Image description

Image description

AUTO SCALING GROUP.
Next is to set our auto-scaling for high availability and scalability. Firstly, let create a launch template that will be attached to the auto scaling.

Image description
Next, is to launch a new instance and attached the new image as AMI.

Image description

Image description

Image description

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x58v220lrtuxcii8pdvs.jpg

CONCLUSION
We successfully launched a fully functional web application leveraging the power of Amazon Web Services (AWS). By utilizing a Virtual Private Cloud (VPC) for secure networking, Elastic Block Store (EBS) for persistent storage, AWS CloudWatch for real-time monitoring, and Auto Scaling Groups for dynamic scalability, we ensured our web application is highly available, scalable, and resilient.

This deployment showcases the effectiveness of AWS services in building a robust and efficient web infrastructure, capable of handling diverse workloads and adapting to changing demands.

Top comments (0)