How to Install Nginx on CentOS 6

Introduction

Nginx is a free and open-source high performance web server software, popular for its stability, simplicity in configuration and low resource consumption. In this tutorial also, the user needs to have root privileges for execution of commands.

Installation of EPEL

For the installation of nginx using yum command, you will have to include the EPEL i.e., Extra Packages for Enterprise Linux. Yum as a package manager will not have the latest version of nginx in its default repository. So, you need to install EPEL in order to ensure that nginx on CentOS is up to date.

Open up your terminal and run the command for installing EPEL.

sudo  'rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm'

 

Installation of Nginx

Open up the terminal and just run the command to install nginx.

sudo yum install nginx

You will be asked to import the EPEL gpg-key since it’s the first package installed using EPEL.

warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID 217521f6

warning: rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY

Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

Importing GPG key 0x0608B895:

Userid : EPEL (6)

Package: epel-release-6-5.noarch (installed)

From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

Is this ok [y/N]: y

Once you enter yes to the system prompt and the gpg-key has been imported, then nginx will get installed on your virtual private server.

 

Starting Nginx

To start nginx, you need to type in the following command. Nginx does not start automatically.

sudo /etc/init.d/nginx start

Now, verify the nginx installation on your VPS by navigating to your IP address in browser. Get your server’s IP address by running:

ifconfig eth0 | grep inet | awk '{ print $2 }'

The welcome screen will be displayed and you are done with the installation.

KB Admin has written 46 articles