## Introduction
Setting up a web server is an essential step for hosting websites, APIs, and applications. A keyskill required as a DevOps engineer. In this blog post, I'll walk you through the process of installing and configuring NGINX on an AWS Ubuntu 24.04 instance. I'll also share insights, challenges encountered, and how they were resolved.
## AWS as a Cloud Platform
AWS (Amazon Web Services) is one of the leading cloud service providers, offering a range of infrastructure solutions for hosting, computing, and networking. Learning to configure and deploy services on AWS is a crucial skill for anyone aspiring to be a Cloud Infrastructure Engineer.
## Launching the AWS Ubuntu Server
To begin, an AWS EC2 instance was launched with the following specifications:
- AMI: Ubuntu 24.04 LTS
- Instance Type: t2.micro
- Key Pair: SSH key pair for secure access
-
Security Group Configuration:
- Inbound Rule: Port 22 (SSH) allowed for remote access
- Additional configurations added later for HTTP access
After launching the instance, I connected to it via SSH using:
ssh -i my-key.pem ubuntu@<public-ip>
## Updating the Ubuntu System
Before proceeding with any software installation, it is good practice to update the system package list and upgrade existing packages:
sudo apt update && sudo apt upgrade -y
This ensures that all installed packages are up to date, minimizing potential conflicts.
## Installing NGINX
NGINX is a powerful web server that also functions as a load balancer and reverse proxy. To install it, I executed the following command:
sudo apt install nginx -y
Once installed, NGINX automatically starts running. To verify its status, I ran:
sudo systemctl status nginx
A successful installation and running status indicated that the service was active and operational.
## Editing the Default Web Page
NGINX serves an HTML file from /var/www/html/index.html
by default. To customize the default page, I attempted to edit the file:
nano /var/www/html/index.html
However, I encountered a Permission Denied error because the file is owned by the root
user.
### Challenge: Permission Issues
Since the /var/www/html/index.html
file belongs to the root
user, the default ubuntu
user did not have write access. Best practices suggest using appropriate user permissions instead of switching to the root user.
### Solution: Editing with Elevated Privileges
For this project, I temporarily switched to the root user to modify the file:
sudo su
nano /var/www/html/index.html
After editing and saving the changes, I exited the root user mode:
exit
Alternatively, a safer approach would be to change the file ownership:
sudo chown ubuntu:ubuntu /var/www/html/index.html
nano /var/www/html/index.html
This method allows the ubuntu
user to edit the file without switching to root.
## Restarting NGINX and Allowing HTTP Traffic
After modifying the HTML file, I restarted the NGINX service to apply the changes:
sudo systemctl restart nginx
By default, NGINX listens on port 80 (HTTP). To allow public access, I updated the AWS security group settings to include an inbound rule for HTTP:
- Protocol: TCP
- Port Range: 80
- Source: 0.0.0.0/0 (Allows public access)
After updating the security group, I accessed the NGINX welcome page through my public IP address in a web browser:
http://<public-ip>
The modified page successfully loaded, confirming that NGINX was serving my customized HTML content.
## Conclusion
This experience provided valuable insights into setting up and configuring NGINX on an AWS Ubuntu 24.04 server. The key takeaways include:
- Updating the system before installing new packages.
- Understanding user permissions when modifying system files.
- Properly configuring the security group to allow external HTTP access.
- Recognizing AWS as a powerful cloud platform for hosting and infrastructure management, an essential skill for Cloud Infrastructure Engineers.
By following these steps, you can deploy your own NGINX-powered web server on AWS with minimal hassle!
Top comments (0)