Two-tier web server Setup & Deployment Strategy
Created an Nginx Reverse Proxy web server
About-Its a Simple To-Do web Application Built in Java SpringBoot and React
as per the Assignment Question For the web application consisting of a frontend and a single backend service in the same server we will be deploying our Application on the single Nginx & Reverse Proxy server(Backend service)
Clone the Repository
git clone https://github.com/alvinsenjaya/to-do-list-spring-boot-react.git
Two separate folder for Backend And Frontend
Install Nginx Web Server to host the frontend or Web Server
sudo apt update sudo apt install nginx
Install NodeJs and Npm to Build The Frontend server
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash source ~/.bashrc nvm install --lts node -e "console.log('Running Node.js ' + process.version)" #install node V.20 install successfully now below commands for dependency and build npm install # Install dependencies npm run build # Build the production-ready optimized bundle
Note-
As per the Configuration First we will run our application on locallhost then will deploy on EC2 only build FilesBuild & Run Commands for both Backend And Frontend Server
#for Frontend Server npm install npm run build npm run production # for Backend Server # Install java 17 and maven go to that Backend Directory run following Command for Backend server mvn clean mvn install # below is the SS for the Output
Frontend Build Ready !
Backend Build Ready ! wooho
Check the localhost Application is working Fine
Home Page
we can see All URL starting with "api/" are directed to the Backend service as per the Requirement
Add New Todo App Page todo Successfully Added
View Todo Page Task added Successfully while communicating with Backend
Nginx Reverse Proxy File available in
cd etc/nginx/sites-available/
Expected Output
Dockerfile for Backend & Frontend
FROM openjdk:17-oracle
WORKDIR /backend
COPY target/to-do-list-0.0.1-SNAPSHOT.jar /backend/app.jar
CMD ["java","-jar","app.jar"]
FROM ubuntu
# Install Nginx & dependencies
RUN apt-get update && \
apt-get install -y nginx && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Copy Nginx configuration
COPY nginx.conf /etc/nginx/nginx.conf
# Copy our frontend build files
COPY build /var/www/html/
# Expose port 80
EXPOSE 80
# Start Nginx service
CMD ["nginx", "-g", "daemon off;"]
Infrastructure Write-up
EC2 Instance Configuration :
Launch an EC2 instance using an appropriate instance type based on our application's resource requirements.Install Following Dependencies : or run
./dependencies.sh
#!/bin/bash # Update package lists sudo apt update # Install Java 17 sudo apt install -y openjdk-17-jdk # Install Maven sudo apt install -y maven # Install Node.js sudo apt install -y nodejs # Install Nginx sudo apt install -y nginx # Install Docker sudo apt install docker.io
Scalability
Auto Scaling: Implement auto-scaling policies to automatically adjust the number of EC2 instances based on metrics such as CPU utilization, memory usage, or incoming traffic.
Load Balancing: Introduce an Elastic Load Balancer (ELB) to distribute incoming traffic across multiple EC2 instances. This improves fault tolerance and handles sudden spikes in traffic effectively we for this deployment we can use Network load balancer because it has low latency compare to ALB.
Maintainability
Infrastructure as Code (IaC): Use tools like AWS CloudFormation or Terraform to define and manage the infrastructure as code. This allows for easy replication of the infrastructure across multiple environments and simplifies maintenance tasks.
Reliability
High Availability: Deploy the web application across multiple Availability Zones (AZs) to ensure high availability and fault tolerance
Monitoring and Alerting: Set up monitoring and alerting for key metrics such as server health, application performance, and infrastructure utilization Tools Like AWS Cloudwatch, Uptime-Kuma, Grafana etc.
Subscribe to my newsletter
Read articles from Dhruv Vats directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by