Deploying a website is like scoring the perfect goal-it takes strategy, execution, and precision. Recently I launched a static website on AWS using Nginx, and the whole process felt like setting up the perfect play and scoring the winning goal.
Here's how I did it, step by step.
Project Goal - Winning Formation
The objective of this project was to:
- Launch an Ubuntu EC2 instance on AWS.
- Install and configure Nginx to serve a custom HTML page.
- Ensure accessibility via a public IP address.
Play-by-Play Execution
1. Launching and EC2 Instance (Picking the Right Stadium)
I started by launching an Ubuntu t2.micro EC2 instance(free-tier eligible), allocated 8GB of EBS storage and attached a pre-configured security group to it, allowing traffic on port 80 (HTTP). Additionally, I deployed the instance in a public subnet and ensured my existing key pair was attached for SSH access. Then I connected to the instance through SSH.
2. Installing Nginx (Putting the Striker in Position)
Next was to install Nginx, started the service, and ensured it would automatically start on boot with the following commands:
sudo apt update
sudo apt install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx
sudo systemctl status nginx
At this point, Nginx should be running, and I could confirm this by visiting the public IP address of my EC2 instance in a web browser.
3. Uploading Website Files (Passing the ball)
At this point I was ready to create the very simple website file and save it as index.html using the following command:
echo "[Website content]" >> index.html
Then I copied the index.html file to /var/www/html/ directory path.
4. Restarting Nginx and Testing the Deployment (Final Whistle: GOAL!)
After modifying the index.html file, I restarted Nginx to apply the changes:
sudo systemctl restart nginx
Finally, I accessed my public IP address in a browser, and my custom webpage loaded successfully.
Challenges and Solutions
While this was a straightforward task, I encountered a few minor challenges:
Security Group Configuration: Initially, I couldn’t access the webpage. After troubleshooting, I realized I had to allow inbound HTTP traffic on port 80 in both the Security Group and Network ACL settings.
Permission Issues: While editing the index.html file, I encountered permission errors. Using sudo
resolved the issue, ensuring I had the necessary privileges.
Reflections and Key Takeaways
This task served as a great refresher on AWS EC2, security configurations, and web server deployment. Some key lessons learned include:
Always ensure security group rules settings permit required traffic.
Using systemctl enable nginx
ensures the service starts automatically after a reboot.
Proper file permissions are crucial when modifying files in /var/www/html/.
For beginners, this exercise provides a solid foundation in cloud computing and DevOps practices.
Further Resources
Looking for professional DevOps and Cloud Engineers? Check out:
DevOps Engineers - https://hng.tech/hire/devops-engineers
Cloud Engineers - https://hng.tech/hire/cloud-engineers
Conclusion
Deploying a basic Nginx server on AWS is a simple yet essential skill in cloud computing. Whether you're learning DevOps or just starting your cloud journey, practicing such hands-on projects will help reinforce your knowledge.
Feel free to drop any questions in the comments or share your own experience with setting up Nginx on AWS!
🚀 Happy Coding!
Top comments (0)