DEV Community

Mukumbuta
Mukumbuta

Posted on

DevOps - NGINX Configuration

Introduction

As part of my DevOps learning journey, I was tasked with setting up and configuring NGINX on a fresh Ubuntu server. This exercise tested my ability to deploy a simple web server, configure it to serve a custom webpage and make it accessible to the public. In this blog post, I will walk you through my approach, the challenges I faced, and what I learned from the experience.


Approach & Steps Taken

Step 0: Setting Up a Domain Name

The first step I took was to buy a domain name from godaddy.com, created a subdomain and pointed it to the VPS.

Step 1: Setting Up an Ubuntu Server

The second step was to get an Ubuntu server up and running. I chose Namecheap VPS with the following specifications:

  • OS: Ubuntu 22.04 LTS
  • CPU: 8 CPU
  • RAM: 12GB
  • Storage: 32GB
  • Public IP: Assigned automatically

I connected to the server using SSH:

ssh myusername@my-server-ip
Enter fullscreen mode Exit fullscreen mode

Step 2: Installing NGINX

Once inside the server, I updated the package list and installed NGINX:

sudo apt update && sudo apt upgrade -y
sudo apt install nginx -y
Enter fullscreen mode Exit fullscreen mode

To verify that NGINX was installed and running, I used:

sudo systemctl status nginx
Enter fullscreen mode Exit fullscreen mode

Opening http://server-IP/ in a browser confirmed that NGINX was serving its default welcome page.

Step 3: Configuring NGINX to Serve a Custom Web Page

The next step was to create an Nginx server block for this specific task.
A server block in Nginx is a configuration section that defines how Nginx handles requests for a specific domain or IP address.

I then created a symbolic link in Nginx by linking the configuration file from /etc/nginx/sites-available/ to /etc/nginx/sites-enabled/. This allows Nginx to recognize and use the configuration when it reloads.

sudo ln -s /etc/nginx/sites-available/devops /etc/nginx/sites-enabled/
Enter fullscreen mode Exit fullscreen mode

The folowing step was to replace the default NGINX page with a custom one. I created a file index.html file:

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

I then coded in the appropriate HTML according to the task.
After saving the file (CTRL + O, then Enter, then X), I restarted NGINX to apply the changes:

sudo systemctl restart nginx
Enter fullscreen mode Exit fullscreen mode

Visiting http://server.gateway.tumingle.com/ in a browser now displayed the custom message.

Step 4: Configuring Firewall for Public Access

To ensure that my server was accessible from the internet, I checked the firewall settings and allowed HTTP traffic:

sudo ufw allow 'Nginx Full'
sudo ufw enable
sudo ufw status
Enter fullscreen mode Exit fullscreen mode

This confirmed that traffic on port 80 was open.

The last step was to issue an SSL certificate using certbot/nginx combination using the command:

sudo certbot --nginx -d server.gateway.tumingle.com.
Enter fullscreen mode Exit fullscreen mode

Now I could view the site over HTTPS.


Challenges & How I Overcame Them

1. NGINX Not Running After Installation

At first, NGINX failed to start. Running sudo systemctl status nginx showed a port conflict. The issue was caused by another web service running on port 80. I resolved it by stopping the conflicting service:

sudo systemctl stop apache2
sudo systemctl disable apache2
sudo systemctl restart nginx
Enter fullscreen mode Exit fullscreen mode

2. Firewall Blocking HTTP Requests

Even after configuring NGINX, my site was inaccessible. Checking the firewall rules (sudo ufw status) revealed that port 80 was not open. Enabling the necessary firewall rules fixed this.

3. HTML Page Not Updating

After editing index.html, my browser still showed the old page. This was due to caching. I cleared the cache with CTRL + SHIFT + R and also restarted NGINX:

sudo systemctl restart nginx
Enter fullscreen mode Exit fullscreen mode

What I Learned from This Experience

  1. Understanding Web Server Basics – I learned how to install, configure, and manage NGINX, which is a fundamental skill for DevOps engineers.
  2. Working with Firewalls – Managing firewall rules was a key takeaway, ensuring my server was accessible while maintaining security.
  3. Troubleshooting and Debugging – Debugging issues with services like NGINX, checking logs, and resolving conflicts helped improve my problem-solving skills.
  4. Cloud and Server Administration – Setting up a cloud-based virtual machine, securing it, and hosting a web application is essential knowledge for anyone entering the DevOps field.

How This Task Contributes to My Professional Growth

This exercise gave me hands-on experience with NGINX deployment, an essential skill for DevOps Engineers. It also reinforced my ability to troubleshoot issues and work with Linux servers, which are crucial in modern cloud environments.


Conclusion

Completing the DevOps Stage 0 - NGINX Configuration task was a valuable learning experience. It reinforced my understanding of web server deployment, Linux administration, and troubleshooting. This hands-on practice has prepared me for more advanced DevOps and cloud computing challenges.

Next Steps:

  • Deploy a similar setup using Docker to containerize the application.
  • Explore load balancing with NGINX for handling multiple requests efficiently.
  • Automate the setup using Ansible or Terraform.

This task has been an exciting first step in my DevOps journey, and I look forward to learning more! 🚀


What’s Next for You?

Have you ever set up NGINX on a server? What challenges did you face? Let me know in the comments!


References

Top comments (0)