DEV Community

Omachoko Tanimu Yakubu
Omachoko Tanimu Yakubu

Posted on

DEPLOYING NGINX ON AWS EC2: MY HNG12 STAGE 0 EXPERIENCE

INTRODUCTION

As part of the HNG12 internship (under the DevOps track), I was tasked with deploying an NGINX web server on any cloud service of my choice. I chose Amazon Web Services and setup an Ubuntu Server EC2 instance. This involved launching the virtual machine, configuring security rules, and automating the installation of NGINX. In this blog post, I’ll walk you through my experience, the challenges I faced, and my key takeaways.

SETTING UP THE EC2 INSTANCE

Step 1: Launching an Ubuntu Server on AWS

To begin, I created a free tier account and logged into AWS Management Console, then I navigated to EC2. I then clicked "Launch Instance", where I configured the following:

Ubuntu Server 24.04 LTS as the operating system Amazon Machine Image (AMI)

Image description
Image description

t3.micro instance (Free Tier eligible)

Image description

8 GiB of storage (gp3 SSD)

Image description

Enabled Auto-assign Public IP so my server could be accessed from the internet

Image description

Step 2: Configuring Security Groups

Since the instructions strictly required only HTTP (port 80) access, the following custom security group with the following rule was created:

Inbound Rule:

HTTP (Port 80) → Source: 0.0.0.0/0 (anywhere on the internet).

Outbound Rule:

All traffic allowed (default AWS setting).
I did not enable SSH (port 22) since it was not allowed per the instructions.

AUTOMATING NGINX INSTALLATION

Since SSH access was blocked, I couldn’t manually install NGINX. Instead, I used User Data, a feature that runs commands automatically when an instance is created.

Step 3: Configuring NGINX in User Data

Before launching the instance, I scrolled down to Advanced Details → User Data and pasted the following script:

!/bin/bash

sudo apt update -y
sudo apt install nginx -y echo 'Welcome to DevOps Stage 0 - Omachoko Yakubu/ChockqOteewy' | sudo tee /var/www/html/index.html
sudo systemctl restart nginx

Configuration of NGINX using User Data under Advanced Settings

Image description

This script:

Installs NGINX.

Creates an index.html file with a custom message.

Ensures NGINX restarts so the changes take effect.

Details of Instance After Launching

Image description

VERIFYING THE DEPLOYMENT

Step 4: Checking the NGINX Web Page

After launching my instance, I copied its Public IPv4 Address from the AWS EC2 Dashboard and visited the public address of my server:

http://13.60.179.5/

Since the setup was successful, the browser displayed the following message:

Welcome to DevOps Stage 0 - Omachoko Yakubu/ChockqOteewy

Image description

Success! My NGINX web server was running perfectly.

CHALLENGES AND HOW I OVERCAME THEM

A major challenge I faced while setting up NGINX on an Ubuntu Server in AWS was thinking I needed to connect to the VM manually before running the script. I later discovered that I could input the script directly as part of the initial setup in the Advanced Details section under User Data, which made the process much easier.

KEY TAKEAWAYS

I learned how to deploy and configure NGINX on AWS without SSH access.

I practiced using User Data to automate server setup.

I gained a deeper understanding of AWS EC2 security groups and instance management.

USEFUL RESOURCES

Learn more about DevOps Engineers: https://hng.tech/hire/devops-engineers

Explore AWS Solutions Architects: https://hng.tech/hire/aws-solutions-architects

Top comments (0)