DEV Community

Cover image for Deploying Nginx on AWS: A Beginner-Friendly Guide(HNG DevOps Stage 0)
Whuatorhe Tejiri
Whuatorhe Tejiri

Posted on

Deploying Nginx on AWS: A Beginner-Friendly Guide(HNG DevOps Stage 0)

Introduction

Configuring an Nginx web server on AWS is a fundamental skill for anyone diving into cloud computing and DevOps. This project focuses on setting up an Ubuntu-based EC2 instance to host a simple HTML page using Nginx. Through this process, I gained practical experience in server provisioning, web server configuration, and basic networking.

In this blog, I’ll walk you through the steps I took to achieve this, the challenges encountered, and key takeaways.

Project Goal

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.

Step-by-Step Implementation

1. Launching an EC2 Instance

I started by launching an Ubuntu EC2 t3.micro instance, which falls under the AWS free tier. While setting up the instance, I allocated 8GB of EBS storage and attached a pre-configured security group 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.

2. Connecting to the Instance

Once the instance was running, I connected to it using SSH:

ssh -i "my-key.pem" ubuntu@

After successfully logging in, I updated the package lists to ensure my system had the latest software packages:

sudo apt update

3. Installing and Configuring Nginx

Next, I installed Nginx, started the service, and ensured it would automatically start on boot:

sudo apt install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx
sudo systemctl status nginx

At this point, Nginx was running, and I could confirm this by visiting the public IP address of my EC2 instance in a web browser.

nginx running

4. Deploying a Custom HTML Page

To serve a personalized webpage, I created a new index.html file with custom HTML and CSS content:

sudo vim /var/www/html/index.html

I then added a simple HTML page with basic styling, saved the file, and exited the editor.

5. Restarting Nginx and Testing the Deployment

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.

nginx-webserver

Challenges and Solutions

While this was a straightforward task, I encountered a few minor challenges:

Security Group and NACL 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 and NACL 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!

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

Retry later