How to Install Nginx on CentOS 9 Stream

Estimated reading: 3 minutes 416 views

Nginx (Engine X) is the most popular, powerful web server software that can be used on your server. It is also known for its high performance and low memory usage. In addition to its HTTP server capabilities, NGINX can also function as a proxy server for e-mail (IMAP, POP3, and SMTP) and a reverse proxy and load balancer for HTTP, TCP, and UDP servers.

Here at Fixwebnode, as part of our Server Management Services, we regularly help our Customers perform related Nginx queries. In this tutorial, we will show you how to install Nginx on CentOS 9 Stream.

1. Install Nginx on CentOS 9 Stream

Step 1: Perform System Update

To begin, ensure that your system is up-to-date with the below command:

# yum update
Step 2: Install Nginx on the system

By default, Nginx is available on the CentOS 9 Stream base repository. Now we run the following command to install Nginx to your system:

# yum install nginx

Once the installation is complete, enable Nginx (to start automatically upon system boot), start the web server, and verify the status using the commands below:

# systemctl start nginx
# systemctl enable nginx
# systemctl status nginx

To verify the Nginx version, use the following command to confirm:

# nginx -v

Step 3: Configure Firewall

If a firewall protects your server you need to open both HTTP (80) and HTTPS (443) ports:

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

# firewall-cmd --permanent --zone=public --add-service=https

# firewall-cmd --reload 
Step 4: Verify Nginx Installation

Once successfully installed, open http://your-IP-address in your browser of choice, and you will see the default Nginx welcome page as shown in the image below:

2. Nginx Configuration File’s Structure.

You don’t need to configure Nginx upon installation. However, you should know the location of the configuration files and the Nginx root directory in case you need to modify the configuration.

  • Nginx configuration directory: /etc/nginx
  • Nginx root directory: /usr/share/nginx/html
  • Master/Global configuration file: /etc/nginx/nginx.conf

3. Nginx Management Commands

Other than starting and enabling the Nginx server commands (as discussed above), there are a few more commands that you will find helpful in managing the Nginx server. We are sharing some of them:

To stop the Nginx service, the command would be:

# systemctl stop nginx

To restart the Nginx service, the command would be:

# systemctl restart nginx

To disable the Nginx service, the command would be:

# systemctl disable nginx

When you make any configuration changes, you will need to reload the firewall configuration. Here is the command you can use:

# systemctl reload nginx

4. Uninstall Nginx

If you ever need to remove/uninstall Nginx from your CentOS machine, you can do so as follows:

Stop Nginx services as follows:

# systemctl stop nginx.service

Then to remove Nginx, use the command below:

# yum remove nginx

To remove Nginx configuration and log files too, use the command below:

# rm -R /etc/nginx
# rm -R /var/log/nginx

Good luck!

1 Comment

  • ashraaf

    June 5, 2024

    I want to add an RTMP module and confgure the NGINX server on CentOS 9 Stream, for live streaming, please give further details on this topic.


Leave a Comment