NGINX Web Server on CentOS 8

Dane Forslund
3 min readApr 13, 2022

--

Organizations can access and test their webpage over their CentOS 8 server, using NGINX for their content storage and delivery needs. You can use this as a guide to install and run NGINX as well as set up firewall for security.

1. Connect to the server

First, you will want to open a secure shell (ssh) in your ssh client (Terminal) to connect to your CentOS 8 enabled server.

To do this, enter the following:

ssh <username>@public_ip_address

You will be prompted to enter your password.

Now, lets check for any updates to the server:

sudo yum check-update

If there are some updates, use command:

sudo yum update

2. Update firewall for security:

To add HTTP and HTTPS service to the firewall, add:

sudo firewall-cmd --permanent --add-service=httpsudo firewall-cmd --permanent --add-service=https

Reload the firewall for changes to apply:

sudo firewall-cmd --reload

Lastly, we will open port 80 and 443 using firewall-cmd:

sudo firewall-cmd --permanent --zone=public --add-service=http

Again we will add this for changes to apply:

sudo firewall-cmd --reload

To check the status of the firewall:

systemctl status firewalld

You should see a screen similar to this:

NGINX3. Install and Run the NGINX package:

sudo yum search nginx

After entering your password, the server will search for the package and should be listed like this:

Once listed, you may install using:

sudo yum install nginx

If your server is ready, you will see a nice, “Complete!”

To enable and run NGINX, add:

sudo systemctl enable nginx

followed by

sudo systemctl start nginx

You can check the status with:

sudo systemctl status nginx ##

It should look like this:

Congrats!

You are now utilizing NGINX on CentOS 8!

4) Let’s Verify

If you would like to verify your work via the internet, you can use your public IP address. Just enter the following:

curl -I

Use the displayed IP address, and go to “http://your_public_ip_address”

If the installation was successful, it should look similar to this:

Bonus:

Let’s host a simple HTML website on our NGINX Webserver

First, the location in your Linux filesystem where web content is stored, is /usr/share/nginx/html. Change directories to that location:

cd /usr/share/nginx/html

Next, let’s remove the current index.html:

sudo rm index.html

Then using nano (a text editor), we will create our own index.html file:

sudo nano index.html

Add your content (Here is the example html code I used to create my website):

<!DOCTYPE html><html><head><title>Congrats, you did it!</title></head><body><h1>Lets LEVEL UP!!!</h1><p>Welcome to LUIT - Go Team Red!</p></body></html>

When finished, hit “control” and “X”. Then save by pressing “y”.

To test out your website, simply refresh the website page, or go to “http://your_public_ip_address”

Thank you for reading!

--

--

Dane Forslund
Dane Forslund

Written by Dane Forslund

DevOps | Cloud | AWS enthusiast. I believe my most successful moments have derived from patient leadership, proactive resolve, and often adversity.