
Nginx pronounced engine x
is a free, open-source, high performance HTTP and reverse proxy server. It is a modern and efficient web server to handle large number of concurrent connections. Nginx can be used as a standalone web server, reverse proxy for web and other servers, load balancer. It is a much more flexible and lightweight program than Apache HTTP Server. This guide explains how to install nginx on CentOS 8 Server.
Prerequisites
- Before start installation, ensure that you are logged in as a user with sudo privileges.
- Make sure Apache or any other services are not running on port
80
or443
.
Install Nginx on CentOS 8
The Nginx package is included in the CentOS default repositories. It is very straightforward installation for Nginx, Perform the below steps:
sudo yum install nginx
After, completion of installation you need to start and enable the nginx service:
sudo systemctl enable nginx
sudo systemctl start nginx
You can verify that installation is successful or not, run below command:
sudo systemctl status nginx
It should show output as given below:
● 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 2019-12-21 18:18:07 UTC; 45min ago Process: 17772 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS) Process: 17766 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS) Process: 17761 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS) Main PID: 17774 (nginx) Tasks: 2 CGroup: /system.slice/nginx.service ├─17774 nginx: master process /usr/sbin/nginx └─17775 nginx: worker process
Adjusting Firewall
In CentOS 8, the default firewall solutions is FirewallD. By default, at the time of installation of Nginx firewalld service files generated with predefined rules to allowing access to HTTP (80)
and HTTPS (443)
ports.
Run the below commands to open the the necessary ports permanently:
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
That’s it! You can verify your Nginx installation by visiting below URL in your browser:
http://YOUR_SERVER_IP_ADDRESS
It should display default Nginx welcome page, which should look like the image below:

Nginx Configuration Files Structure
- All configuration files are located in the
/etc/nginx/
directory. - Nginx main configuration file is at
/etc/nginx/nginx.conf
. - It’s best practice to create a separate configuration file of each domain for better maintainability.
- New server blocks (configuration file) of each domain should be stored in
/etc/nginx/conf.d
- It’s best practice to to follow standard naming convention. Nginx server block files name should as domain name and must end with
.conf
extension. For example, your domain name isexample.com
then server block file name shouldexample.com.conf
- Nginx log files (
access.log
anderror.log
) are located in the/var/log/nginx/
directory. It’s also recommended to have a different access and error log files for each server block. - The default server web root directory is
/usr/share/nginx/html
. It is flexible to set your domain document root to any directory wherever you want. Some of most used locations are:- /var/www/html/here_your_domain_name
- /var/www/here_your_domain_name
- /home/username/here_your_domain_name
- /usr/share/nginx/html/here_your_domain_name
Conclusion
Finally, you have successfully installed Nginx on your CentOS 8 Linux. Manage Nginx services and start to deploy your applications.
If you have any question or suggestion, feel free to comment below.
Leave a Reply