Creating a NGINX Web Server

Joey Slawinski
4 min readJul 23, 2022

--

HI All,

This week I tackled creating a Linux Server with NGINX and displayed a quick html file as a website. I documented the items below on how to use it. We are currently using Ubuntu through an AWS environment, and this was completed through a terminal process. We are also going to tackle updating some packages to ensure our system is updated.

For those who aren’t familiar with NGINX it is a free, open-source software for hosting websites. The capabilities are quite vast for this software but for this exercise walkthrough we will keep it simple with publishing a website.

Step 1 Connecting:

To get this lesson started we are either going to open up a terminal window if using Mac or a PowerShell window if on Windows OS. Once the window is open simply type the below line of text or copy it into your window.

ssh username@publicip

Step 2 Updating Packages:

The second command we are going to type tells the system to update the software packages. Type or copy the commands below. This might take a minute to verify that all the packages are up to date. The first command is actually going to update the repository for the packages and the second command will update the packages themselves. To ensure the packages are up to date make sure you run both commands. This will ask you for your credentials to your machine as well.

Command 1: sudo apt update

Command 2: sudo apt upgrade

Step 3 Installing NGINX:

Once those commands have finished running, we are ready to install NGINX. Below is the command that you can install NGINX from. It will ask you if you are sure you want to continue. Provide the letter y to continue.

sudo apt install nginx

Step 4 Changing the Default Webpage:

Once your install has completed, we will adjust the default webpage to display when we browse to it. There are a couple commands to run during this process. The first command we have to run is we need to change our directory to match where the file is for the webpage. This can be done by command one below. The second command is going to allow us to edit the webpage. Once we are inside the webpage proceed to the next step where we will display our name and some additional text on the site.

Command 1: cd /var/www/html

Command 2: sudo vi index.nginx-debian.html

Step 5 Replacing the Websites Text:

This step will focus on replacing the website with text of our own. You are now inside of VIM which is the text editor on Linux. You should see the website code with a lot of HTML and other verbiage. For this part you do not need to worry about what the code means, just that we are going to change it. Right now, you are unable to edit the code, but by pressing the letter i you can insert new text into it. Once you press the letter i, delete all the contents out of that document and replace it with the items below.

Content:

<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”utf-8">
<me=”viewport”
content=”width=device-width, initial-scale=1, user-scalable=yes”>

<title>Hello World!</title>
</head>
<body>
Hello World! This is Your Name’s First Website!

</html>

Step 6 Saving and Viewing Webpage:

At this point you have inserted the website text into the file and now we need to save it. Press the escape key while inside the editor and then press :wq to save the file and quit.

Now the last thing to do is to browse to our website. You should have the public IP address of your machine since you used it by logging into the machine through the terminal. We are going to browse to that address, and you should see your webpage above.

Webpage: http://yourpublicip

Note although not necessary sometimes a restart of the service triggers a refresh of the website. See below command if needed.

Command: sudo service nginx restart

Here is my webpage working after the steps above!

Source for hello world html document: Hello World in plain HTML (code-maven.com)

NGINX Web Server Picture Source: https://qph.fs.quoracdn.net/main-qimg-391eef262c2f2e1c34bfa264274ac456

--

--