DEV Community

Uduakabasi Umo-Odiong
Uduakabasi Umo-Odiong

Posted on

CONFIGURING NGINX ON AN FRESH UBUNTU SERVER

OVERVIEW
This is simply a blog post highlighting my approach and the steps I took to configure Nginx on an Ubuntu server. This was the first task for my HNG 12 Internship and I am happy to share the steps in case you ever get a similar task.

INTRODUCTION
Nginx is a fast and efficient web server that helps deliver websites quickly and manage traffic. In this task, we will configure nginx on an Ubuntu AWS instance(virtual server) and then create and launch a custom HTML page on the server. The Virtual Server is where the Nginx web server will be deployed.

PREREQUISITE

  1. An AWS Account
  2. A Terminal

STEPS
Step 1: Create your ubuntu server(AWS EC2 Instance)
Create an Ubuntu server, and download the keypair for the instance to your device. It is important that when setting up your security group you allow inbound rules for SSH and HTTP.

Image description

Image description

Step 2:Connect to your instance
To Connect to your instance, on your terminal change your present working directory to the directory where you downloaded your private key pair, copy the command to make your keypair private and the ssh command then go to the terminal and make the keypair private then ssh into the server.

Image description

Image description

Step 3: Install the Nginx Web server
Update your terminal and install nginx running the commands
sudo apt update
sudo apt install nginx -y

Image description

Image description

Step 4:configure the Nginx Web server
At this point, you start up the server, confirm its status that it is actually running and then ensure whenever the ec2 instance restarts, the nginx server starts automatically.

-To start the server and verify its status enter the following commands
sudo systemctl start nginx
sudo systemctl status nginx

Image description

-To enable the nginx server and ensure starts automatically enter the command
sudo systemctl enable nginx

Image description

Step 5:Run the default nginx webpage
Copy your public IP address from your AWS instance and paste it into a fresh tab once you hit enter the NGINX webpage should be on display

Image description

Image description

Step 6:Customize your Nginx Default Web Page
Navigate to the Directory with the default index.html file which is /var/www/html/ and create a custom index.html file which will contain your custom code. Using any text editor of your choice, enter the code for your custom code, save and then refresh the tab with the IP address of your instance.

Image description

Image description

Image description

Image description

CHALLENGES AND SOLUTIONS
I. Understanding the task: This was due to the way the project was communicated. The details of the task were confusing at first read.
Solution: I carefully read what was required of me over and over again till I understood and ensured that I picked out the key details that needed to be included in the task.

ii. Connecting to my Instance using SSH: This was because in the past I had mistakenly deleted my Internet gateway and I did not realize this until today.
Solution: I utilized documentation and videos to see what I missed then noticed the missing internet gateway.

LESSONS AND CONTRIBUTIONS TO PROFESSIONAL GOAL
The major lesson here was how to set up my server on Ec2, connect to my terminal using SSH and install/customise the Nginx Server. This has contributed significantly and added to my knowledge and experience of Deploying web servers which is on a need-to-know basis for a Cloud/DevOps Engineer.

CONCLUSION
This task has better equipped me with how to go about deploying web servers on a Cloud platform and how to handle obstacles when performing any task. This article is highly recommended for anyone trying to configure Nginx on an Ubuntu Server and feel free to reach out in situations where you get stuck or to give feedback. Thank you for reading.

ps: Incase you need a professional for this sort of task reach out or visit the websites below.
DevOps Engineers - https://hng.tech/hire/devops-engineers
Cloud Engineers - https://hng.tech/hire/cloud-engineers

Top comments (1)

Collapse
 
ovrobin profile image
Victor Robin

Nice work Uduak, this was insightful.

I will consult this article when I need to set up a Nginx server too.