Introduction
As part of the DevOps Stage 0 task, I was required to install and configure NGINX on an Ubuntu server, setting up a custom HTML page as the default page. To demonstrate automation skills, I chose to deploy this setup on an AWS EC2 instance using user-data scripting for automatic configuration.
Approach
To complete this task, I followed these steps:
1. Launching the EC2 Instance
- Logged into AWS and navigated to EC2 Dashboard.
- Created a new Ubuntu 22.04 LTS instance.
- Chose t2.micro (free-tier eligible).
- Configured security group rules to allow SSH (port 22) but forgot to open HTTP (port 80) initially.
- Attached a key pair for secure SSH access.
2. Using User-Data for Automated Setup
To automate the NGINX installation and configuration, I used the following user-data script:
#!/bin/bash
sudo apt update && sudo apt upgrade -y
sudo apt install -y nginx
sudo systemctl enable nginx
sudo systemctl start nginx
echo "<html><body><h1>Welcome to DevOps Stage 0 - Afeez Adeboye/A.A</h1></body></html>" | sudo tee /var/www/html/index.html
sudo systemctl restart nginx
3. Encountered Issues and Fixes
Issue 1: Port 80 Not Open
Since I relied on user-data for configuration, I initially forgot to open port 80 in the security group. As a result, I thought NGINX was not working. Fix: I manually updated the security group to allow HTTP (port 80).
Issue 2: Browser Redirecting to HTTPS
When I tried accessing the instance via a web browser, it kept redirecting to HTTPS, but the project only required HTTP. Fix: I had to explicitly type http://
instead of relying on automatic redirection.
Final Verification
Once the fixes were applied:
- Visiting
http://<EC2-PUBLIC-IP>
displayed:
Learning & Takeaways
This task reinforced key DevOps concepts, including:
✅ Automating server setup using user-data.
✅ Managing AWS security groups effectively.
✅ Troubleshooting web server issues related to ports and protocols.
✅ Understanding how NGINX serves static files.
Hiring DevOps and Cloud Engineers
If you're looking to hire skilled professionals in DevOps or Cloud Engineering, check out these resources:
Top comments (0)