• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Install Nginx on CentOS 8

Written by Admin, Updated On December 22, 2019
centos, nginx
How to Install Nginx on CentOS 8

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 or 443.

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-default-page

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 is example.com then server block file name should example.com.conf
  • Nginx log files (access.log and error.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.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article Less Command in Linux
Next Article   How to Install Git on Debian 10 Linux

Related Posts

  • How to Install Nginx on Ubuntu 22.04

    How to Install Nginx on Ubuntu 22.04

    January 28, 2023
  • How to Install Php 8 on CentOS 8

    How to Install PHP 8 on CentOS 8

    January 27, 2021
  • How to Install Python 3.9 on CentOS 8

    How to Install Python 3.9 on CentOS 8

    December 31, 2020

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install SSH Keys on Ubuntu 22.04
    How to Set up SSH Keys on Ubuntu 22.04 January 7, 2023
  • How to Install Mongodb on Debian 11
    How to Install MongoDB on Debian 11 Linux January 11, 2023
  • How to Install Puppet Agent on Ubuntu 22.04
    How to Install Puppet Agent on Ubuntu 22.04 January 22, 2023
  • How to Install Jenkins on Debian 11
    How to Install Jenkins on Debian 11 January 5, 2023
  • How to Change-Hostname Ubuntu 22.04
    How to Change Hostname on Ubuntu 22.04 January 19, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook