Let’s Set Up a NGINX Web Server in CentOS 8!

Christopher Lawshe
4 min readOct 12, 2022

--

This project was as huge first step for me in learning more about using Linux. It also served as a great learning experience for me in my goal of becoming a cloud DevOps engineer.

Let’s get into it!

Prerequisites : access to a Linux CentOS 8 server (physical or virtual)

STEP 1: Update All Packages on your CentOS 8 server

Keeping your server’s packages up to date is general good practice and a necessary part of administration in a live environment. If this is not done we may run into issues running new programs due to outdated libraries installed on our system(s).

  1. ) First we will want to check and see the updates available for all installed packages, then download and cache all the metadata known for all repositories. Complete this by typing ‘sudo dnf check-update’ [enter], then ‘sudo dnf makecache’ [enter]
type ‘sudo dnf check-update’ to check updates available for all installed packages
type ‘sudo dnf makecache’ to downlaod and cache all metadata known for all repositories on your system. This will display all updates available for the system.

2. ) Next we will run the upgrade on the system by typing ‘sudo dnf upgrade’ [enter].

type ‘sudo dnf upgrade’ to execute the upgrade process for all repositories on CentOS 8 server

Once this is done we have completed our upgrade and finished Step 1!

STEP 2: Install NGINX Web Server

For us to use the NGINX service on our system, we first need to install it to our CentOS server.

From CentOS CLI we will type ‘sudo dnf install nginx’ [enter]. Then type ‘y’ [enter] to initiate the installation.

The resulting output shows the dependencies being resolved and installed.

The install will begin and notify us when complete.

STEP 3: Enable NGINX Web Server

In order for our Web Server to be accessibe through the internet we need to enable it and activate HTTP/HTTPS protocol.

  1. ) From CentOS CLI we’ll type ‘sudo systemctl enable nginx’ [enter] (we’ll be prompted for your password here) and then ‘sudo systemctl start nginx’ [enter]. NGINX is now enabled on our CentOS server!
‘sudo systemctl enable nginx’ and ‘sudo systemctl start nginx’ tells NGINX to turn on and start running on our CentOS server

2. ) Once NGINX is running, we have to make the server available by enabling HTTP/S. To do so we need to type out a two commands:

  • sudo firewall-cmd --permanent --add-service=http’ [enter], and
  • ‘sudo firewall-cmd --permanent --add-service=https’ [enter]

3. ) After this, we must verify the system took the commands by typing:

  • sudo firewall-cmd --permanent --list-all’ [enter]

In the resulting text, look for ‘http’ and ‘https’ in the services line. If they are present then we’ve successuflly activated the http/https services!

4. ) All that’s left for us to do now is to apply these changes by reloading our firewall settings. This is done by typing ‘sudo firewall-cmd --reload’ [enter]

That’s it! We’re Done! Well…not quite.

The final and most importatn step in the process is still yet to be done.

STEP 4: Verify our work

To verify our work, we will want to learn the public IP address of our server and try to access it via a web browser.

  1. ) To get our public IP address, we’ll be using a free website called ‘icanhazip.com’ and the ‘curl’ command in CentOS 8.

Let’s type ‘curl -4 icanhazip.com’ [enter] in the CentOS 8 server CLI and see what we get.

‘curl -4 ican hazip.com’ will tell us what our public IP address is

The output of this command will be your public IP address. (It will be different from the one in the above image)

If an IP address is not displayed it is most likely due to your system not having one. In this case, you should verify network connectivity on your CentOS system.

Once you have this address, open a web browser on your computer and enter it into the URL bar. You should be taken to a page that looks like the image below.

If you are taken to a page that resembles the image above then congratualtions, you have successfully installed and configured a NGINX Web Server from your Linux CentOS server!

--

--

Christopher Lawshe
Christopher Lawshe

Written by Christopher Lawshe

IT enthusiast — looking to learn from and connect with IT professionals to help push the world forward through Cloud DevOps

No responses yet