How to install Nginx on CentOS


To install Nginx using yum we will need to include the EPEL (Extra Packages for Enterprise Linux) repository.

One thing to keep in mind when adding extra repositories is that many include newer versions of packages that are readily available through the standard channels. This can cause problems as packages can be automatically upgraded and cease to function as expected.

EPEL repository is purely complimentary and only provides additional packages otherwise unavailable through the default repositories.

Installing the EPEL repository

The command will depend on your CentOS version and the machine type (32 or 64 bit):

cat /etc/redhat-release; uname -m

Now, depending on the output, install the EPEL repository:

CentOS 5.x i386:

sudo rpm -ivh

CentOS 5.x x86_64:

sudo rpm -ivh

CentOS 6.x i386:

sudo rpm -ivh

CentOS 6.x x86_64:

sudo rpm -ivh

Installing Nginx using Yum

Installing nginx using Yum is now very simple, thanks to EPEL, run:

sudo yum install nginx

As this will be the first package we install using EPEL, we will be asked to import the EPEL gpg-key.

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

This key is used to sign all packages that are associated with the EPEL repository to verify their validity.

Once the gpg-key has been imported, the installation should proceed as expected.

Starting Nginx

Nginx is not started automatically, to start Nginx run:

# sudo /etc/init.d/nginx start

To check if it works navigate to your IP address:


To start Nginx on boot run:

sudo /sbin/chkconfig nginx on

Controlling Nginx is done with these commands:

sudo /etc/init.d/nginx start
sudo /etc/init.d/nginx stop
sudo /etc/init.d/nginx reload
sudo /etc/init.d/nginx restart

You can also check the current status as well as the configuration syntax by using the following commands:

sudo /etc/init.d/nginx status
sudo /etc/init.d/nginx configtest

The configtest option is particularly useful for testing your Nginx configuration before actually applying it with a reload or restart.


Leave a Reply