Install Nginx on CentOS 7 Operating System

Update on:
Sep 2, 2021

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 7 Operating System.


Before starting the Nginx installation process, make sure you have a CentOS 7 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 7 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:



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

Related Posts

How to Install MongoDB on CentOS 8 Linux

How to Install MongoDB on CentOS 8 Linux

MongoDB is an open-source and free NoSQL document based database system. Nowadays, it is prevalent as most application developers are using MongoDB, which can handle big data. As a MongoDB is a NoSQL database, It stores data in JSON-like documents where fields can...

How to Install OpenCV on CentOS 8 Linux

How to Install OpenCV on CentOS 8 Linux

OpenCV (Open Source Computer Vision Library) is an open-source computer vision and machine learning software library. OpenCV was built to provide a common infrastructure for computer vision applications and to accelerate the use of machine perception in commercial...

How to install and use FFmpeg on CentOS 8 Linux Operating System

How to install and use FFmpeg on CentOS 8 Linux Operating System

The FFmpeg is the most potent and useful command-line tool on Linux system for multimedia files transcoding. You can use FFmpeg to convert multimedia files between various video and audio formats and resize videos. It has multiple audio and video libraries such as...

How to Install VirtualBox on CentOS 8 Linux

How to Install VirtualBox on CentOS 8 Linux

VirtualBox is an Open Source tool, known as a cross-platform virtualization application or software. It used to run multiple operating systems or virtual machines simultaneously on a single hardware. In this VirtualBox installation tutorial, we will explain the...

Follow Us

Our Communities

More on CentOS

The Ultimate Managed Hosting Platform
Load WordPress Sites in as fast as 37ms!



Submit a Comment

Your email address will not be published.

eight + four =