How to Install Nginx on CentOS 8





NGINX is free and open source software. With NGINX you can host websites, perform reverse proxying, cache, load balance, and stream media. Originally, it was intended to serve websites at maximum performance and stability. Igor Sysoev created the software, which was released publicly in 2004. The software is event-driven and asynchronous; allowing multiple requests to be processed simultaneously. In addition, the NGINX system is highly scalable, so it grows as its clients’ traffic increases. Installing Nginx on CentOS 8 is covered in this tutorial.







Step 1: Configure VPSie cloud server



  1. Sign in to your system or register a newly created one by logging in to your VPSie account. 
  2. Connect by SSH using the credentials we emailed you.
  3. Once you have logged into your CentOS 8 instance and update your system.




Check if the box needs any updates,



# sudo yum updateinfo



Run the command if it is available,



# sudo dnf update





If you are using a new server, Make sure you have sudo privileges and no other processes are running on ports 80 or 443.  







Step 2: Installing Nginx





Nginx packages are included in the default repositories.Use the following command to install Nginx.



# sudo yum install nginx



Nginx should be enabled and started as follows,



# sudo systemctl enable nginx

# sudo systemctl start nginx




Check the status of the service to make sure it’s running:



# sudo systemctl status nginx





[email protected] ~]# sudo systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2021-12-25 12:03:23 EST; 10s ago
  Process: 12376 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 12374 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 12373 ExecStartPre=/usr/bin/rm -f /run/ (code=exited, status=0/SUCCESS)
 Main PID: 12378 (nginx)
    Tasks: 2 (limit: 4504)
   Memory: 8.3M
   CGroup: /system.slice/nginx.service
           ├─12378 nginx: master process /usr/sbin/nginx
           └─12379 nginx: worker process







Step 3: Firewall configuration






Centos 8 comes with FirewallD as the default firewall. A firewalled service file is created when Nginx is installed that contains predefined rules for accessing HTTP (80) and HTTPS (443) ports. Open the following ports permanently with 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




You can verify Apache is working by typing the IP address or domain name of your server into your web browser. This will display a welcome message similar to the following:








Step 4: Managing Nginx






So you’ve got your web server running, let’s talk about a few basic management commands.




# sudo systemctl stop nginx




The web server can be started by typing the following command:



# sudo systemctl start nginx




The service can be stopped and then restarted by typing:



# sudo systemctl restart nginx




Apache often reloads without losing connections. Simply run the following command:



# sudo systemctl reload nginx







Structure of the Nginx Configuration File





  • The main configuration file for Nginx is /etc/nginx/nginx.conf.


  • Files relating to Nginx configuration reside in the /etc/nginx/ directory.


  • The log files for Nginx can be found in the /var/log/nginx/ directory. You should have separate access and error logs per server.


  • Block files for Nginx servers must end in .conf and reside in /etc/nginx/conf.d directory.


  • It is easier to maintain the server if every domain has its own configuration file.



  • Following naming conventions is recommended. If, for instance, the domain is, the configuration file would be






We have successfully installed the Nginx web server on your computer. Hopefully, you have found this article useful and gained some useful information from it. Thank you for reading.







Try VPSie for free today!