How to Install Nginx on CentOS 8

Install Nginx on CentOS 8

In this article, we will have explained the necessary steps to install and configure Nginx on CentOS 8. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Nginx pronounced “engine x” is an open-source, high-performance HTTP and reverse proxy server responsible for handling the load of some of the largest sites on the Internet. It can be used as a standalone web server, load balancer, content cache, and reverse proxy for HTTP and non-HTTP servers.

Install Nginx on CentOS

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

Step 2. Install Nginx on CentOS 8.

Now that the repository is added, it’s time to install Nginx:

Once it is installed, start and enable the Nginx service by typing:

To verify that the service is running, check its status:

Step 3. Configure Firewall.

If you are running a firewall, run the following commands to allow HTTP and HTTPS traffic:

Step 4. Accessing the Nginx.

Now, you can test your Nginx installation, by opening http://YOUR_IP or http://YOUR_DOMAIN in your web browser. You should see the default Nginx welcome page.

Step 5. Nginx Configuration File’s Structure.

  • Default Server Root

The default server root directory is /usr/share/nginx/html. Files that are placed in there will be served on your web server. This location is specified in the default server block configuration file that ships with Nginx, which is located at /etc/nginx/conf.d/default.conf.

  • Server Block Configuration

Any additional server blocks, known as Virtual Hosts in Apache, can be added by creating new configuration files in /etc/nginx/conf.d. Files that end with .conf in that directory will be loaded when Nginx is started.

  • Nginx Global Configuration

The main Nginx configuration file is located at /etc/nginx/nginx.conf. This is where you can change settings like the user that runs the Nginx daemon processes, and the number of worker processes that get spawned when Nginx is running, among other things.

That’s all you need to do to Install Nginx Web Server on CentOS 8. I hope you find this quick tip helpful. If you have questions or suggestions, feel free to leave a comment below.