DEV Community

Cover image for NGINX web server Configuration/HNG Internship(Phase 0)
Tony Uketui
Tony Uketui

Posted on

NGINX web server Configuration/HNG Internship(Phase 0)

Before we delve into configurations and all that.

You might be wondering...

Tony, What the heck is Nginx and why is it one of the most popular web servers used.

Before anything,

A web server is simply anything that stores, processes, and delivers web pages to users. It handles requests from web browsers (like Chrome) and sends back the requested content, such as websites, images, videos, or data.

if that seems too complex.

Imagine you walk into a restaurant and order Fried rice with chicken.

Fried Rice

Here’s how the process works:

You (the browser) make a request → You tell the waiter your order.
The waiter (web server) processes it → He goes to the kitchen and gets your food.

The kitchen (database/backend) prepares the food → If the food is ready, he brings it immediately; if not, he tells you it’s unavailable (404 error).

The waiter serves you (delivers the web page) → You enjoy your Fried rice (website content).

But before we talk about Nginx...
let's talk about this other web server called Apache

Nginx came into place because of Apache's major limitation.

which was...

Not doing well under heavy traffic because of it's (Process/thread based nature)

And thats when Nginx came into the picture.

Nginx

So what exactly is Nginx.

What is Nginx?
Nginx is a high-performance web server that also functions as a reverse proxy, load balancer, and HTTP cache. It is widely used for handling high amounts of traffic efficiently and is known for its speed, scalability, and lightweight resource usage.

Unlike Apache that is process/thread based. It is Event-driven

To Keep it simple it can do the following;

  1. It can handle thousands of requests without consuming too many system resources.(lightweight)

  2. It Distributes traffic across multiple servers, improving availability and reliability.(load-balancing)

  3. It Reduces latency by storing frequently requested data.(speed)

So now we understand Nginx

Lets quickly set up some configurations to serve our web page.

Pre-requisites:

  • Linux Machine(in my case, i used ubuntu)
  • key pair(ssh)
  • NGINX
  • Application ode
  • Internet Connection

Here's My Approach to do this.

To start,i launched an ec2 instance to get my ubuntu machine running and connected to it via ssh.

ubuntu server

I needed to install Nginx on my Linux machine. This was a relatively straightforward task. Using the package manager on my system (Ubuntu), I ran the following commands to install Nginx:

  • sudo apt update && sudo apt install nginx -y

Once installed, I enabled the service to start on boot and immediately started it by running:

  • sudo systemctl enable nginx
  • sudo systemctl start nginx

boot

After installation, I verified the Nginx service was running using:

  • sudo systemctl status nginx

nginx

Seeing the service running was a satisfying confirmation that I was on the right track.

The next step was to configure Nginx to serve a custom HTML page as the default page. I modified the default index.html file located in /var/www/html/index.html and replaced its contents with:

code

I then restarted Nginx so changes in my configurations would reflect. using the below command

  • sudo systemctl restart nginx

restart

It works!

browser

I know it's not the prettiest but it works.

Here's the link to check if it works on your end.
http://98.81.253.140/

In terms of challenges, i didnt really encounter much as this was a pretty straightforward task.

But...

Here are some common challenges people face while trying to set this up:

  • Firewall isssues,(make sure http isn't blocked)
  • Permission issues(solved by using sudo) e.t.c

Also, this task helped me improve my web server management skills, which are essential in any DevOps role. By learning how to install, configure, and troubleshoot Nginx,

I now have a deeper understanding of how web servers function and how to ensure they are running smoothly.

Additionally, configuring Nginx as a web server is a foundational skill for DevOps Engineers and cloud engineers, both of which are roles I aspire to fill.

This task directly aligns with my long-term goals of working with cloud-based applications and building scalable web architectures.

Speaking of DevOps and Cloud engineers...

HNG connects companies with top tier talents suited to their needs.

So if you are in need of elite and top tier DevOps and Cloud engineers to handle your cloud infrastructure and DevOps related tasks

Explore elite and specialized talents for hire:

Top comments (0)