Web servers are fundamental to DevOps, forming the backbone of web applications by handling requests and serving content efficiently. As part of the HNG DevOps Stage 0 task, I installed and configured NGINX on a fresh Ubuntu server to serve a custom HTML page. This task helped me solidify my understanding of web server configurations, system administration, and automation. In this blog post, I will walk through the step-by-step process of setting up NGINX, the challenges I faced, and the key learnings from this experience.

Task Requirements

The objective of this task was to:

  • Install the NGINX web server on a fresh Ubuntu instance.
  • Configure it to serve a custom HTML page at /var/www/html/index.html with the message:
"Welcome to DevOps Stage 0 - [Your Name]/[SlackName]"

(Replacing [Your Name] with my real name and [SlackName] with my Slack username.)

  • Include links to DevOps Engineers and Cloud Engineers resources.

Step-by-Step Implementation

1. Installing NGINX

Before installing NGINX, I updated the package repository to ensure I was fetching the latest software versions:

sudo apt update && sudo apt upgrade -y

Then, I installed NGINX using the following command:

sudo apt install nginx -y

Once the installation was complete, I started and enabled the NGINX service:

sudo systemctl start nginx
sudo systemctl enable nginx

To verify that NGINX was running successfully, I checked its status:

systemctl status nginx

A green "active" status confirmed that NGINX was operational.

2. Configuring NGINX to Serve a Custom HTML Page

NGINX serves files from /var/www/html/ by default. I edited the index.html file in that directory to display my custom message.

sudo nano /var/www/html/index.html

I replaced the existing content with the following HTML:

<!DOCTYPE html>
<html>
<head>
    <title>DevOps Stage 0</title>
</head>
<body>
    <h1>Welcome to DevOps Stage 0 - [Your Name]/[SlackName]</h1>
    <p>Explore more about DevOps roles:</p>
    <ul>
        <li><a href="https://hng.tech/hire/devops-engineers" target="_blank">DevOps Engineers</a></li>
        <li><a href="https://hng.tech/hire/cloud-engineers" target="_blank">Cloud Engineers</a></li>
    </ul>
</body>
</html>

After saving and exiting (CTRL + X, then Y, and pressing Enter), I restarted NGINX to apply the changes:

sudo systemctl restart nginx

3. Testing the Configuration

To verify that my setup was successful, I accessed the server's IP address in a web browser:

http://your-server-ip

Alternatively, I used curl to fetch the web page:

curl http://localhost

Seeing my custom message confirmed that the NGINX setup was complete.

Challenges Faced and Solutions

1. NGINX Not Starting

Issue: When I initially tried to start NGINX, I encountered an error stating that the service failed to start.

Solution: Checking the logs with sudo journalctl -u nginx --no-pager revealed that another service was using port 80. I identified the conflicting service using:

sudo netstat -tulnp | grep :80

Stopping the conflicting service and restarting NGINX resolved the issue:

sudo systemctl stop apache2
sudo systemctl disable apache2
sudo systemctl restart nginx

2. Changes Not Reflecting in Browser

Issue: After modifying index.html, my browser still displayed the old page.

Solution: I cleared the browser cache and restarted NGINX. I also verified file permissions to ensure NGINX had read access:

sudo chmod 644 /var/www/html/index.html
sudo systemctl restart nginx

Key Learnings from This Task

  1. Understanding Web Server Deployment: Setting up and configuring NGINX deepened my understanding of web server management and static content delivery.
  2. Troubleshooting System Services: Debugging NGINX startup issues provided hands-on experience with Linux system services and networking.
  3. Automation Possibilities: This manual process highlighted the potential for automating server setup with tools like Ansible or Terraform.

How This Task Supports My Career Goals

Completing this task is a stepping stone in my DevOps journey. The ability to configure web servers is essential for DevOps Engineers, who manage infrastructure and CI/CD pipelines. Understanding how NGINX serves as a reverse proxy and load balancer is also valuable for roles like Site Reliability Engineers and Cloud Engineers.

If you're looking to hire professionals in these fields, check out:

This hands-on experience has reinforced my ability to work with production-grade web servers, a critical skill in modern DevOps practices.

Conclusion

Setting up NGINX from scratch on an Ubuntu server was an insightful exercise in configuring and troubleshooting a web server. From installation to serving a custom web page, this task helped me build a solid foundation in Linux system administration and web server management. As I continue my DevOps learning path, I look forward to automating such deployments using Infrastructure as Code (IaC) tools like Terraform and Ansible.

This challenge was a rewarding experience, and I am excited about more DevOps tasks ahead in the HNG program!

Author Of article : bankolejohn Read full article