How to Install Nginx on CentOS 7

GINX (short for Engine X) is a free, open-source and powerful HTTP web server and reverse proxy with an event-driven (asynchronous) architecture. It is written using C programming language and runs on Unix-like operating systems as well as Windows OS.
It also works as a reverse proxy, standard mail and TCP/UDP proxy server, and can additionally be configured as a load balancer. It is powering many sites on the web; well known for its high-performance, stability and feature-rich set.
In this article, we will explain how to install, configure and manage Nginx HTTP web server on a CentOS 7 or RHEL 7 server using command line.

Install Nginx Web Server

1. First update the system software packages to the latest version.
# yum -y update
2. Next, install Nginx HTTP server from the EPEL repository using the YUM package manager as follows.
# yum install epel-release
# yum install nginx 
Install Nginx on CentOS 7
Install Nginx on CentOS 7

Manage Nginx HTTP Server on CentOS 7

3. Once Nginx web server installed, you can start it first time and enable it to start automatically at system boot.
# systemctl start nginx
# systemctl enable nginx
# systemctl status nginx
Start and Enable Nginx at Boot
Start and Enable Nginx at Boot

Configure firewalld to Allow Nginx Traffic

4. By default, CentOS 7 built-in firewall is set to block Nginx traffic. To allow web traffic on Nginx, update the system firewall rules to permit inbound packets on HTTP and HTTPS using the commands below.
# firewall-cmd --zone=public --permanent --add-service=http
# firewall-cmd --zone=public --permanent --add-service=https
# firewall-cmd --reload
Allow Nginx on Firewalld
Allow Nginx on Firewalld

Test Nginx Server on CentOS 7

5. Now you can verify Nginx server by going to the following URL, a default nginx page will be shown.
http://SERVER_DOMAIN_NAME_OR_IP 
Test Nginx Installation
Test Nginx Installation

Nginx Important Files and Directories

  • The default server root directory (top level directory containing configuration files): /etc/nginx.
  • The main Nginx configuration file: /etc/nginx/nginx.conf.
  • Server block (virtual hosts) configurations can be added in: /etc/nginx/conf.d.
  • The default server document root directory (contains web files): /usr/share/nginx/html.
You may also like to read these following Nginx web server related articles.
In this article, we showed how to install and manage Nginx HTTP server from the command line on CentOS 7. You can ask questions or give us any feedback via the comment form below.
Previous
Next Post »

Bài đăng phổ biến