How to Install Nginx on CentOS 8

Nginx, stylized as NGIИX, is a web server that can also be used as a reverse proxy, load balancer, mail proxy and HTTP cache. The software was created by Igor Sysoev and publicly released in 2004. Nginx is free and open-source software, released under the terms of the 2-clause BSD license

NGINX is open source software for web serving, reverse proxying, caching, load balancing, media streaming, and more. It started out as a web server designed for maximum performance and stability.

Install Nginx on centOS 8; Through this tutorial, we will learn how to install Nginx on CentOS 8.

How to Install Nginx on CentOS 8

Follow the following steps to install Nginx on CentOS 8:

  • Step 1 – Install Nginx on CentOS
  • Step 2 – Enable and Start Nginx
  • Step 3 – Verify Status of Nginx
  • Step 4 – Adjust Firewall
  • Step 5 – Nginx Configuration File’s Structure

Step 1 – Install Nginx on CentOS

First of all, open terminal or command line and execute the following command into it to install Nginx on CentOS 8:

sudo yum install nginx

Step 2 – Enable and Start Nginx

Once the nginx installation is completed, then execute the following command on command line or terminal to enable and start nginx:

sudo systemctl enable nginx
sudo systemctl start nginx

Step 3 – Verify Status of Nginx

Once the start and enable nginx, execute the following command on command line or terminal to verify status of nginx:

sudo systemctl status nginx

Step 4 – Adjust Firewall

Execute the following command on command line or terminal to adjust firewall settings:

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

Step 5 – Nginx Configuration File’s Structure

And use the following instrucations to configure file’s in nginx:

  • All Nginx configuration files are located in the /etc/nginx/ directory.
  • The main Nginx configuration file is /etc/nginx/nginx.conf.
  • Creating a separate configuration file for each domain makes the server easier to maintain.
  • The Nginx server block files must end with .conf and be stored in /etc/nginx/conf.d directory. You can have as many server blocks as you want.
  • It is a good practice to follow a standard naming convention. For example, if the domain name is mydomain.com then the configuration file should be named mydomain.com.conf
  • If you use repeatable configuration segments in your domain server blocks, it is a good idea to refactor those segments into snippets.
  • Nginx log files (access.log and error.log) are located in the /var/log/nginx/ directory. It is recommended to have a different access and error log files for each server block.
  • You can set your domain document root directory to any location you want. The most common locations for webroot include:
    • /home//
    • /var/www/
    • /var/www/html/
    • /opt/
    • /usr/share/nginx/html

Conclusion

Install Nginx on centOS 8; Through this tutorial, we have learned how to install Nginx on CentOS 8.



Images mentioned above related to CentOS,NGINX are either copyright property of respective image owners.

Rabins Sharma Lamichhane

Rabins Sharma Lamichhane is senior ICT professional who talks about #it, #cloud, #servers, #software, and #innovation. Rabins is also the first initiator of Digital Nepal. Facebook: rabinsxp Instagram: rabinsxp

Leave a Reply

Your email address will not be published. Required fields are marked *