How to Install Nginx on CentOS 8

Abidoye Joshua mayowa
4 min readJan 21, 2023

--

INTRODUCTION

Thanks for checking my first medium post. For the past two weeks have had the opportunity to work on Linux and play around with it. To hone my skills in Linux, I created an Nginx server on centos 8.

NGINX is open-source software for web serving, reverse proxying, caching, load balancing, media streaming, and more. It started as a web server designed for maximum performance and stability. In addition to its HTTP server capabilities, NGINX can function as a proxy server for email (IMAP, POP3, and SMTP) and a reverse proxy and load balancer for HTTP, TCP, and UDP servers.

Prerequisites:

To complete this project, you will need access to a command line interface and a Centos 8-enabled server. This server must have sudo privileges for a non-root user.

Step 1

Login to your CentOS 8 system using SSH. Do this by entering the following:

ssh cloud_user@public_ip_address

Then you need to enter your password.

Step 2: Update Packages

we will need to update the virtual machine by using the command below.

sudo yum update

The system will prompt you to reenter your password. The server will then run the updates. Your screen will then show that the updates have been completed or that no updates were needed. An example:

Step 3: Install Nginx

To install Nginx, we need to run the command below.

sudo yum install nginx

The system will ask if you want to proceed, type "y" and tap enter. It will start the process.

You will receive a complete message if you run the required code above.

Step 4: Check the status of Nginx

Check the status of Nginx to see if it's active and working.

sudo systemctl status nginx

If it's running, your system will look like the image above.

Step 5: Enable or Start

In case your Nginx is inactive, you will need to enable and start it to activate the server:

sudo systemctl enable nginx
sudo sytemctl start nginx

After that, we can recheck the status by running the same command in Step 4:

Now the Nginx is active and running.

Step 6:Enable firewall

We need to enable the firewall so it can transfer traffic to the web:

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

The next step is to reload the firewall to apply these changes:

sudo firewall-cmd --reload

Step 7: Locate the IP address and run the website

We need an IP address to see if the web server is running:

curl -4 icanhazip.com

We need to copy the IP address on a new tab on our web browser to confirm if the server is running. If it worked, we should get something like the image attached below.

Congratulations, the web server is now running.

Step 1: Create a bash file

To start this, we will need to create an empty editor.

sudo vi nginx.sh

Vi is the visual editor we will use to make our Bash script.

nginx will be our name, and .sh is called the shell script

An empty editor will appear after writing the above command.

Step 2: Input the order

The first command we will need for every bash script is called (shebang), and it's attached below:

#!/bin/bash

This will help instruct our operating system to use the file as a command interpreter

The next thing will be inputting all the commands from above:

After typing all the commands in the script, press ESC on your keyboard, :wq and tap enter. This will save the file that you just wrote.

Step 3: Execute the script

Finally, to run the file, we need to execute the file by running the command below:

chmod +x nginx.sh

And follow it up with the following command:

./nginx.sh

Which is the relative path of the file that we want to execute.

That's the end of the tutorial.

Thanks for reading and following along.

--

--

Abidoye Joshua mayowa
Abidoye Joshua mayowa

Written by Abidoye Joshua mayowa

DevOps Engineer. I'm interested in collaborating with anyone interested in cloud engineer or cloud DevOPs.

No responses yet