Nginx is an open-source high-performance web server that is often used as a reserve proxy with HTTP server capabilities, web server, load balancer, caching- and media streaming software. The structure of Nginx is event-driven which enables it to process multiple requests at the same time. It is more scalable than Apache. Nginx is able to balance the load of large numbers of concurrent connections.

In this article, we will show you step by step how to install Nginx on a CentOS 8 server.

Pre-requisites

Before starting the installation, you will make sure that you don’t have any process that is running on port 80 or 443.

Installation of Nginx on CentOS 8

The following steps you will perform to install Ngnix on your system:

Log in as a root user on your system.

Open the terminal window by accessing the search bar from Activities. Or you can open using Ctrl + Alt + t shortcut keys.

Open Linux Terminal

By default, Nginx is available in CentOS 8 repositories. So, you can install it using yum package manager on your system. To install Nginx type the following command on the terminal:

$ sudo yum install nginx

Install Nginx You will see a user confirmation prompt on the terminal. You will press ‘y’ and ‘Enter’ to continue the installation of Nginx packages.

Confirm installation

After a while, a ‘complete’ status will display on the terminal that will show Ngnix has been successfully installed on your system.

Installation finished

Once the installation of Nginx is completed, now you will enable the Nginx service on your system by using the following command:

$ sudo systemctl enable nginx

Enable Nginx service

In the next step, we will start the Nginx service on your system using the following command:

$ sudo systemctl start nginx

Start Nginx

Now, we’ll verify that the Ngnix service is running. For this purpose, type the following command on the terminal:

$ sudo systemctl status nginx

Check Nginx status

Adjust firewall settings

In CentOS 8 the default solution of firewall is ‘Firewalld’. During the Nignx installation, a firewalld service file is created with some predefined set of rules for allowing access to ports HTTP 443 and HTTP 80.

You will permanently open necessary ports using the following commands:

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

Configure the Firewall

Test the Nginx Installation

Now, you will test Nginx installation. For this purpose, first you will check your IP address by using the following command on the terminal:

Test Nginx installation

Now, open your Firefox browser on your system and type http://your_IP in the address bar of your web browser. You will see the Nginx welcome default page in your browser as follows:

Nginx test page

Congratulations, the Nginx server has been successfully installed on your CentOS 8. Now, you’re ready to start deploying your applications and you can use Nginx as a proxy web server.

The configuration files of Ngnix are located in the /etc/nginx/ directory. The main configuration file of Nginx is /etc/nginx/nginx.conf.

Conclusion

In this article, you have learned how you can install Nginx on CentOS 8. Moreover, how to adjust firewall settings on your system using the terminal. I hope you enjoyed this article and it is useful for you. If you have any problem related to this article then let us know through your feedback or comment in the comment box.

How to install Nginx on CentOS 8
Avatar

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.