Tuesday, September 22, 2020

How to Install Nginx on CentOS 8 Operating System

Must read

How to Change Hostname on Ubuntu 20.04 Linux

The hostname is known as the system's identifier, which is set at the time when we are installing the Ubuntu operating system.

How to Install Node.js and NPM on Debian 10 Linux

The Node.js is the very well-known JavaScript runtime environment used to JavaScript code server-side execution. It is an Open-source, cross-platform supported environment....

How to Install Go on Debian 10 Linux

Go is a very new and most popular open-source programming language; Google creates it. There are many popular software/applications developed using the...

How to Deploy Rocket.Chat on Debian 10 Linux

Rocket.Chat is a very popular open-source team communication system; it is famous as an alternative to Slack. It provides various features along...
SATISH KUMAR
I am Satish Kumar, Founder of LinuxConcept. Linux and F.O.S.S enthusiast, love to work on open source platform and technologies.

Nginx, the most popular open-source, HTTP and reverse proxy server with high-performance, use to handle the load of largest sites on the internet.

We can use Nginx as a web server and as a reverse proxy for another web server like Apache.

If we compare Nginx and Apache, Nginx is capable of handling more number of concurrent connections.

In this tutorial article, we will learn how to install Nginx on CentOS 8 Operating System.

Prerequisites

Before starting the Nginx installation process, make sure you have a CentOS 8 running system and a user to log in system with sudo privileges.

You should also make sure the other web server like apache not installed into the system and port 80 and 443 opened from outside.

Nginx install on CentOS

To install high performance web server Nginx, you need to follow below steps:

Step 1 – Enable EPEL repository

The Nginx package is available in EPEL repository, So to install Nginx web server first need to install EPEL repository if it is not in your server. To install EPEL repository type the below command in your terminal and press Enter.

$ sudo yum install epel-release

Step 2 – Install Nginx

Once the EPEL repository installs in your system, you can install Nginx by using the following command:

$ sudo yum install nginx

Step 3 – Enable and start Nginx Service

After successful installation of the Nginx web server, you should enable the Nginx service to make it auto-start on system start and start the Nginx service by using the following command:

$ sudo systemctl enable nginx
$ sudo systemctl start nginx

You can verify the Nginx service is running properly by checking the status of Nginx service, as shown below:

$ sudo systemctl status nginx

If service is running correctly you will get the screen with Active and running status as below image:

Step 4 – Configure Firewall for Port 80 and 443

If your server’s firewall configured you should configure it for port http and https also so your web server reachable from the outside, to perform firewall configuration you should execute below command on terminal:

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

Step 5 – Verify Nginx installation

To verify Nginx web server is installed and running properly, you should open your serer IP into any web browser with typing address in the address bar like http://YOUR_IP, if you get the below screen means Nginx is running properly:

Nginx Services manage with systemctl

CentOS 8 comes with systemctl to manage service; you can manage Nginx service with systemctl like below examples.

To stop the Nginx server, type below command:

$ sudo systemctl stop nginx

To start Nginx server use the following command:

$ sudo systemctl start nginx

To restart Nginx server run the below command:

$ sudo systemctl restart nginx

You can reload the Nginx server by using the following command:

$ sudo systemctl reload nginx

To disable Nginx service, so it not auto start on system boot, you can use below command:

$ sudo systemctl disable nginx

To re-enable Nginx service again type:

$ sudo systemctl enable nginx

Nginx important and configuration file structure

  • /etc/nginx/ is the leading directory of the Nginx server; all configuration files located here.
  • /etc/nginx/nginx.conf is the main configuration file of Nginx Server. Create new Nginx server block files with extension “.conf” and it is stored into /etc/nginx/conf.d/ directory.
  • Nginx server always read sites configuration from /etc/nginx/conf-d/ directories.
    It is recommended to make separate configuration files for each site to make changes quickly.
  • Nginx server’s log files saved with name access.log and error.log are located in the /var/log/nginx/ directory.
  • The website files you can store in any location and set the path into configuration files but commounly used webroot directories are below:

/var/www/<site_name>
/var/www/html/<site_name>
/usr/share/nginx/html
/home/<user_name>/<site_name>
/opt/<site_name>

Conclusion

Now you have learned how to install Nginx Web Server on CentOS 8. You are ready to deploy any website or application behind Nginx web server.

- Advertisement -

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article

How to Change Hostname on Ubuntu 20.04 Linux

The hostname is known as the system's identifier, which is set at the time when we are installing the Ubuntu operating system.

How to Install Node.js and NPM on Debian 10 Linux

The Node.js is the very well-known JavaScript runtime environment used to JavaScript code server-side execution. It is an Open-source, cross-platform supported environment....

How to Install Go on Debian 10 Linux

Go is a very new and most popular open-source programming language; Google creates it. There are many popular software/applications developed using the...

How to Deploy Rocket.Chat on Debian 10 Linux

Rocket.Chat is a very popular open-source team communication system; it is famous as an alternative to Slack. It provides various features along...

How to Install Tomcat 9 on Ubuntu 20.04 Operating System

The Apache Tomcat software is an open source implementation of the Java Servlet, JavaServer Pages, Java Expression Language and Java WebSocket technologies. Apache...