**
Introduction
**
I started an internship journey at HNG Cohort 12 on the DevOps track.
My first task was to setup and configure NGINX on a fresh Ubuntu Server. This task will demonstrate my ability to work with basic web server configurations, and deliver a functional web server.
**
Project Deliverables:
**
Install the NGINX web server and ensure it is running
Configure NGINX to serve a custom HTML page as the default page
Plan
As an AWS Solutions Architect, I decided to make use of Amazon EC2 instances running on Ubuntu engine to configure NGINX
I also challenged myself further to provision the EC2 instance using AWS CLI (Command Line Interface). With that the majority of this project was done on a Linux terminal, no GUIs or Management Console.
STAGE 1; Provision EC2 Instance
Signed into AWS CLI using Access ID, and Keys. Specified the Region (af-south-1) and the output format. Used this command to configure CLI;
aws configure
To provision an EC2 instance, I'll need a keypair and security group
aws ec2 create-key-pair --key-name MyKey --query 'KeyMaterial' --output text > MyKey.pem
chmod 400 MyKey.pem
aws ec2 create-security-group --group-name MySecurityGroup --description "Allow SSH access"
Confirmed that the Security group was created
Allowed SSH on the security group
aws ec2 authorize-security-group-ingress --group-name MySecurityGroup --protocol tcp --port 22 --cidr 0.0.0.0/0
Next stage was to launch the EC2 Instance.
The EC2 instance used Ubuntu Server 24.04 LTS (HVM),EBS General Purpose (SSD) Volume Type. Ensured that it was a free-tier instance to avoid incurring cost.
aws ec2 run-instances --image-id ami-1234567890abcdef0 --count 1 --instance-type t3.micro --key-name MyKey --security-groups MySecurityGroup
Confirmed that the instance was successfully deployed.
Also retrieved the instance details on the CLI
The next step was to SSH (connect) into the EC2 instance
ssh -i MyKey.pem ubuntu@<EC2_PUBLIC_IP>
STAGE 2
Deploy NGINX on EC2
First step is to update the system package list;
sudo apt update && sudo apt upgrade -y
Install NGINX
sudo apt install nginx -y
Start the NGINX service:
sudo systemctl start nginx
Enable it to run at startup:
sudo systemctl enable nginx
At this point NGINX was successfully installed, but I encountered a problem. To test the server, I'd enter the IP address into a web browser, and it should load the NGINX default page successfully but it didn't.
I then realized that the Security group of the EC2 instance didn't allow traffic from HTTP port 80.
To allow HTTP traffic (port 80) for everyone (0.0.0.0/0): I used the following command
aws ec2 authorize-security-group-ingress --group-id sg-0abc123def456gh78 --protocol tcp --port 80 --cidr 0.0.0.0/0
Verify That Port 80 is Open
aws ec2 describe-security-groups --group-ids sg-0abc123def456gh78 --query "SecurityGroups[*].IpPermissions"
The problem was resolved
Finally to create a custom HTML page:
Remove the default page
sudo rm /var/www/html/index.nginx-debian.html
Create a new index.html file
echo "<h1>Welcome to My NGINX Server on AWS EC2!</h1>" | sudo tee /var/www/html/index.html
sudo systemctl restart nginx
Final Test
Challenges
- Connecting to the server from a browser due to the firewall rules
Key Takeaways
Installing and configuring NGINX
Systems Administration with Linux and AWS Command Line
Conclusion
Working on this project has helped me better understand the functionality of NGINX. This would be of great value in my Cloud/DevOps Journey.
References
Top comments (0)