How to install Nginx on CentOS 8?

Overview

One of the most widely used web servers in the world, Nginx is in charge of hosting some of the biggest and most well-known websites on the internet. It may be used as a reverse proxy or web server and often uses fewer resources than Apache.

You will discover how to set up Nginx on CentOS 8 in this tutorial.

Prerequisites

There are certain prerequisites that need to be met before you begin.

  • A machine running CentOS 8

  • A root user having Sudo privileges

  • Internet connection

Get Started

Step 1. Installing Nginx on CentOS 8

  • Always update the local repository before doing any installations to make sure you are obtaining the most recent software. Use the following command to do it:

sudo yum update
  • Before installing the Nginx package on your system, you can inspect it. Request a copy of the RPM metadata that comes with each RPM package:

sudo yum info nginx
  • Next, execute the following command to install Nginx on CentOS 8:

sudo yum install nginx

As seen in the screenshot above, the result displays a list of the installed Nginx packages.

Step 2. Launching Nginx on Centos 8

Despite the fact that Nginx is installed, the service won't start on its own.

  • To launch the service, type:

sudo systemctl start nginx
  • Use the following command to make it possible for the service to launch at boot time.

sudo systemctl enable nginx
  • Execute the below command to view the service status. Nginx should be active (running).

sudo systemctl status nginx

Stop, Reload or Restart Nginx

  • Stop Nginx: Use this command to terminate Nginx:

sudo systemctl stop nginx
  • Restart Nginx: To halt and restart the service, enter the following command:

sudo systemctl restart nginx
  • Reload Nginx: Use the below command to reload the service without stopping to change the configuration files:

sudo systemctl reload nginx

Step 3. Adjusting Firewall

  • Use the firewall-cmd commands listed below to open and enable ports 80 and 443 on the system firewall so that Nginx web traffic is permitted.

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

Step 4. Testing your Web Server

Now that your server's public IP address or domain name is accessible from a web browser, you may check to see if your Nginx web server is operational.

  • In the terminal, use the following command to view your server's IP address:

ip addr

Open a web browser after that, and then put the IP address (or domain name) into the address bar. The Nginx Welcome Page should then load, indicating that the server has been successfully installed and configured.

Conclusion

This tutorial has shown you how to install and configure Nginx. From here, you have a wide range of options for the technologies and content types that you might utilize in the websites that are hosted on your web server.

Last updated