Grid Guides

Explore How System On Grid Can Work For You

Grid Guide Topics

How To Install Nginx on CentOS 7

Table Of Contents

    ## Table of Contents

    – [Introduction](#introduction
    – [Prerequisites](#prerequisites
    – [Add Nginx Repository](#add-nginx-repository
    – [Install Nginx](#install-nginx
    – [Start Nginx](#start-nginx
    – [Server Root and Configuration](#server-root-and-configuration
    – [Conclusion](#conclusion

    ## Introduction

    [Nginx]( is the popular web server in the world and it is the backbone for hosting most significant sites on the web. It is used as a reverse proxy and it is user-friendly then Apache.

    In this guide, we have discussed Installing Nginx on CentOS 7 server.

    ## Prerequisites

    Before installing Nginx, you should possess regular user with sudo privileges configured on the server.
    You have to do the [Initial Server Setup with CentOS 7](

    ## Add Nginx Repository

    Follow the below command to add the CentOS 7 EPEL repository.

    $ sudo yum install epel-release

    ## Install Nginx

    Now Nginx repository is installed on your server, Now to install Nginx use the below command.

    $ sudo yum install nginx

    Now you will get a prompt, and you have to answer by entering yes, finish your installation on your virtual private server(VPS.

    ## Start Nginx

    You have to start Nginx by entering below command.

    $ sudo systemctl start nginx

    Run the below commands to allow HTTP and HTTPS traffic, If you are running a firewall.

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

    You can check whether the Nginx is installed on your server or not by entering the IP Address in your web browser.


    You will see the below output.


    Now, Your server is installed correctly. Now you have to enable Nginx to start when your system boots. Use the below command to do:

    $ sudo systemctl enable nginx

    Now your Nginx is installed and running.

    To find your server’s public IP Address, find the network interfaces on your machine by entering below command.

    ip addr

    Now you can see the number of interfaces available on your server.


    In the above output, the lo interface is a local loopback interface, which is not we required. The etho interface is required.

    Enter the interface name in the below command to know your server’s public IP address.

    ip addr show eth0 | grep inet | awk ‘{ print $2; }’ | sed ‘s//.*$//’

    ## Server Root and Configuration

    Now we have to know the locations of the Nginx configuration files and default server root directory.

    ## Default Server Root

    The default server root directory is /usr/share/nginx/html. Files which are placed in that server on your web server. This location is specified in the default server block configuration file, that ships with nginx, that is located in /etc/nginx/conf.d/default.conf.

    ## Server Block Configuration

    Virtual hosts in Apache can be added by creating new configuration files in

    Files which are ended with .conf in that directory will be loaded when nginx is started.

    ## Nginx Global Configuration

    The main Nginx Configuration file is located at /etc/nginx/nginx.conf.

    ## Conclusion

    In this guide, we have described how to install Nginx on CentOS 7.