Configuring an NGINX Server on Azure

OmieteOmiete
3 min read

What is Nginx?

Nginx is an open-source web server software known for its high performance and low resource usage. It is designed to handle several connections simultaneously. Nginx enables reverse proxying, caching, load balancing and media streaming.

Deploying a Virtual Machine on Azure

As part of this HNG task, I will install an Nginx server and ensure it runs successfully. I will be using Azure to host the virtual machine where the Nginx server will reside.

This required me logging into my Azure account where I created a virtual machine running on an Ubuntu server. Once my virtual machine was deployed and running, I gained access to it on my local computer using secure shell by typing on the terminal ssh azureuser@20.115.98.128 where azureuser is my virtual machine name and 20.115.98.128 is the public IP address of the virtual machine.

Installing the NGINX Server

In order to configure the Nginx server on my virtual machine, I’d have to update the package list using sudo apt update first, then install the Nginx server using sudo apt install nginx. After the successful installation of the nginx server, I confirmed I could access the server through the public IP address, 20.115.98.128, assigned to my virtual machine.

Configuring the NGINX Server

The Nginx configuration file is where you can specify various settings and directives for your server. This file is crucial for the operation of your Nginx server. It’s typically located at /etc/nginx/nginx.conf, but the location can vary depending on your specific Nginx setup.

The task assigned was to configure NGINX to serve a custom HTML page as the default page (/var/www/html/index.html) with the message: “Welcome to DevOps Stage 0 - [Your Name]/[SlackName]” where I replace [Your Name] with my name and [SlackName] as my slack name.

In order to achieve this, I had to go into the root directory using cd /var/www/html then list the contents of the directory using ls finding only the index.nginx-debian.html file in the directory.

Using sudo nano index.nginx-debian.html, I was able to read and edit the HTML file using the nano file editor.

After configuring the HTML file, I saved and exited the file editor. Before applying the changes, I made sure there were no syntax errors by running the sudo nginx -t command. After making the changes, I reloaded the Nginx server using sudo systemctl reload nginx command to apply the new configuration. I refreshed the Nginx server web page to confirm the changes were made successfully.

Challenges Faced

The main challenge I faced was trying to access the index.html file. A few guides were telling me to access the HTML file through the /usr/share/nginx/html directory which I did. However, after configuration and the nginx server restart, the changes were not applied on the web server even after numerous refreshes. I even had to restart the virtual machine to be sure. Eventually, I read the task assignment again where I read I’d have to access the configuration file in the root directory cd /var/www/html instead, finally finding the index.nginx-debian.html file. I could however only write to the file when using sudo since I was not logged in as a root user, hence using sudo nano index.nginx-debian.html command.

Summary

This task covers accessing a cloud hosting platform (in my case, Azure), using the Linux shell and commands, and configuring a web server. It allowed me to practice my skills in creating an Azure virtual machine, using basic Linux commands to install nginx, navigate directories and edit files, and installing and configuring an Nginx server. It has made me more confident in my skills, and I am excited to see what the future holds.

References

https://dev.to/jimiog/deploying-a-linux-virtual-machine-with-nginx-on-microsoft-azure-1eka

https://medium.com/@grpeto/how-to-change-the-index-html-in-nginx-a-beginners-expedition-0d80047cb58a

https://www.elegantthemes.com/blog/wordpress/what-is-nginx-an-overview-of-the-basics

https://www.solo.io/topics/nginx

https://hng.tech/hire/devops-engineers

https://hng.tech/hire/cloud-engineers

0
Subscribe to my newsletter

Read articles from Omiete directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Omiete
Omiete