DEV Community

Cover image for Deploying an NGINX Web Server on AWS EC2- Stage Zero (0) Project
Emmanuel Oghre
Emmanuel Oghre

Posted on

Deploying an NGINX Web Server on AWS EC2- Stage Zero (0) Project

Introduction
This marks the start of my DevOps journey at HNG Cohort 12.

I was tasked with setting up and configuring NGINX on a fresh Ubuntu server. This task will demonstrate my ability to work with basic web server configurations and deliver a functional web server.
🔧Task Requirements:

NGINX Installation and Configuration

  • Install the NGINX web server and ensure it is running.
  • Configure NGINX to serve a custom HTML page as the default page (/var/www/html/index.html)

Prerequisite for this Project

  • Setup a Cloud Platform Account
  • Download and install a SSH Client
  • Foundational knowledge of edit files in Linux Command Line Interface.

Step 1

Launch AWS account and create an Ubuntu server
Login into the AWS console and click on EC2 (Elastic Compute Cloud)

Image description

Click on launch instance to start a fresh spin-up a new AWS instance

Image description

Type in a name for the server and choose any Ubuntu server image provider and type, in this case I am choosing Ubuntu 24.04 LTS(HVM), SSD Volume Type

Image description
Finalize other prerequisite such as assigning a key-pair and network configuration. I have chose to create a new security group and allow inbound connection on port 80 and 22.

Port 80: allows me to view webpages using the browser connected to the internet, servers responds to client's request via the
80 protocol** which is an application layer protocol primarily used via a web browser.
Port 22: allows me to connect to my server instance to make configurations. It is a secured way to connect to a server via the internet.

Read more about SSH here

Image description
Click on launch instance, you should have your instance up in the EC2 instance window.

Image description

Step 2
Connect to your instance via SSH.
We have many SSH client software choose any and connect to your instance. In this case am using Putty.
Launch putty and insert the server public DNS (Domain Name Server) or Public IP Address.
Click to read more about DNS and IP address.

Image description
After successfully connecting to the server.
Update and Upgrade ubuntu repositories using these commands.

sudo apt update && upgrade
Enter fullscreen mode Exit fullscreen mode

Install NGINX with these commands

sudo apt install nginx -y
Enter fullscreen mode Exit fullscreen mode

Start NGINX

sudo systemctl start nginx
Enter fullscreen mode Exit fullscreen mode

To enbale NGINX at startup

sudo systemctl enable nginx
Enter fullscreen mode Exit fullscreen mode

Image description
Verify if NGINX is installed by copying and pasting the server public ip address like this "http://ipaddress" to see the welcome page.
Note: Replace the ip address with the public ip address of the server earlier created.

Image description
Create a custom HTML page and add these contents in it.

sudo vim /var/www/html/index.html
Enter fullscreen mode Exit fullscreen mode
<!DOCTYPE html>
<html lang="en">
<head>
    <title>My DevOps Project</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #f0f0f0;
        }
        h1 {
            color: #333;
            font-size: 3em;
            text-align: center;
        }
    </style>
</head>
<body>
    <h1>Welcome to DevOps Stage 0 - Emmanuel Christopher Oghre</h1>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Restart NGINX

sudo systemctl restart nginx
Enter fullscreen mode Exit fullscreen mode

Finally test
Use the ip address of the server to test your web page. It should display your custom HTML page like this.

Image description

Challenges

  • I experienced network glitches due to ISP network fluctuations.
  • Putty often timed-out due to inactivity for 5 minutes, I had to re-adjust it to 60 minutes.
  • I had to do a quick recap on HTML, CSS and Markdown basics as its been a while I wrote any line of code.

Key Takeaways
✳️Logging in and spinning up a web server on Amazon Web Service.
✳️Configuring EC2 security groups inbound and outbound port.
✳️Connecting to an instance using SSH.
✳️Installing Nginx and configuring for webpages.

Conclusion
Nginx is invaluable tool in the DevOps workspace used for many purposes. It actualize the inner operation of how webpages are being host and configure to facilitate uninterrupted serving of client's requests. This DevOps journey perfect is packed with the hands-on approach learning need to achieve my dream of becoming a DevOps Engineer in 2025.

References

Top comments (1)

Collapse
 
ameh_mathias profile image
Ameh Mathias Ejeh

Awesome writeup.