How to Install Nginx on CentOS 7

    Posted in Linux Servers on Apr 17, 2018

    linux-vps-hosting.jpg

    NGINX (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

    Prerequisites:

    • A CentOS 7 Server Minimal Install
    • A Rhel 7 Server Minimal Install
    • A CentOS/RHEL 7 system with static IP address

    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.png

    Manage Nginx HTTP Server on CentOS 7

    1. 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.png

    Configure firewalld to Allow Nginx Traffic

    1. 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.png

    Test Nginx Server on CentOS 7

    1. 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 

    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.

    Thanks !