DEV Community

Hamed ayojide
Hamed ayojide

Posted on

Setting Up NGINX on Ubuntu: My DevOps Stage 0 Journey

Introduction

As part of the HNG DevOps Internship, I was tasked with setting up and configuring an NGINX web server on a fresh Ubuntu server. This blog documents my experience, challenges faced, and key takeaways.

Task Overview

The objective was to:

  1. Install and configure NGINX.

  2. Serve a custom HTML page at /var/www/html/index.html with the
    message:

Welcome to DevOps Stage 0 - [Your Name]/[SlackName]
Enter fullscreen mode Exit fullscreen mode
  1. Deploy the server so it’s publicly accessible via an IP address.

  2. Document the process in this blog.

Steps to Complete the Task

1️⃣ Updating the System

First, I updated the package list to ensure I had the latest dependencies:

sudo apt update 
Enter fullscreen mode Exit fullscreen mode

output:

vagrant@Hng-server:~$ sudo apt update
Hit:1 http://us.archive.ubuntu.com/ubuntu focal InRelease
Get:2 http://us.archive.ubuntu.com/ubuntu focal-updates InRelease [128 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu focal-backports InRelease [128 kB]   
Get:4 http://us.archive.ubuntu.com/ubuntu focal-security InRelease [128 kB]    
Get:5 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [3,770 kB]
Get:6 http://us.archive.ubuntu.com/ubuntu focal-updates/main Translation-en [575 kB]
Get:7 http://us.archive.ubuntu.com/ubuntu focal-updates/restricted amd64 Packages [3,545 kB]
Get:8 http://us.archive.ubuntu.com/ubuntu focal-updates/restricted Translation-en [496 kB]
Get:9 http://us.archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [1,254 kB]
Enter fullscreen mode Exit fullscreen mode

2️⃣ Installing NGINX

Next, I installed NGINX using the command:

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

I confirmed the installation with:

nginx -v
Enter fullscreen mode Exit fullscreen mode

3️⃣ Starting and Enabling NGINX

I started the NGINX service and enabled it to launch on boot:

sudo systemctl start nginx
sudo systemctl enable nginx
Enter fullscreen mode Exit fullscreen mode

To verify, I ran:

sudo systemctl status nginx
Enter fullscreen mode Exit fullscreen mode

It showed Active (running), confirming a successful installation.

4️⃣ Configuring the Firewall

Since UFW (Uncomplicated Firewall) was inactive, I allowed HTTP traffic:

sudo ufw allow 'Nginx HTTP'
sudo ufw enable
Enter fullscreen mode Exit fullscreen mode

5️⃣ Creating the Custom HTML Page

I modified the default index.html file to display the required message:

sudo nano /var/www/html/index.html
Enter fullscreen mode Exit fullscreen mode

I replaced the content with:

Welcome to DevOps Stage 0 - [Your Name]/[SlackName]
Enter fullscreen mode Exit fullscreen mode

Then saved and exited using CTRL + X, Y, and Enter.

6️⃣ Restarting NGINX

To apply the changes, I restarted the NGINX service:

sudo systemctl restart nginx
Enter fullscreen mode Exit fullscreen mode

7️⃣ Testing the Web Server

To verify the setup, I ran:

curl http://localhost
Enter fullscreen mode Exit fullscreen mode

This returned the expected message. Finally, I accessed the server from my browser using my public IP address:

http://<your-public-ip>/
Enter fullscreen mode Exit fullscreen mode

Challenges Faced and Solutions

❌ Issue: Page Not Loading in Browser

✅ Solution: I checked my cloud provider’s Security Group Rules (for AWS EC2) and ensured port 80 was open.

❌ Issue: NGINX Not Running After Reboot

✅ Solution: I enabled NGINX to start on boot:

sudo systemctl enable nginx
Enter fullscreen mode Exit fullscreen mode

Key Takeaways

  1. Hands-on Experience: This task reinforced my understanding of
    Linux web servers.

  2. Troubleshooting Skills: Debugging firewall and NGINX issues
    improved my problem-solving abilities.

  3. Practical DevOps Knowledge: Deploying a functional web server
    is a fundamental DevOps skill.

References

As part of the task, I referenced the following resources:

Conclusion

This was a great introduction to NGINX configuration and server deployment. I look forward to more challenging tasks in the internship!

Top comments (0)