CentOS - Installing nginx via yum


Nginx is a popular lightweight server for those who do not need the bulk and extra services that Apache may offer.

This article will look at installing Nginx on a CentOS Server using the 'yum' package manager.

Contents

Yum

Using the inbuilt package manager to install packages is a great idea as it solves dependency issues and you are assured of any security updates if, and when, they occur.

However, one drawback can be that it is rare for a version upgrade to be placed into the repositories. As such, it is possible for a newer version of an application to be released and not be placed into the repository.

EPEL

To install Nginx using yum we will need to include the EPEL (Extra Packages for Enterprise Linux) repository. This repository was developed by the Fedora community to provide extra add-on packages for Fedora-based Redhat Enterprise Linux and it's other compatible offspring such as CentOS.

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.

I want to make it clear that the EPEL repository is purely complimentary and only provides additional packages that are otherwise unavailable through the default repositories.

Versions

At the time of this writing the latest stable version of Nginx was 0.6.34. You can check the latest versions and change logs at the main nginx site.

If you decide you would rather have a later version of Nginx than the one the EPEL repository provides, please refer to the sister article to this one, which will take you through the process of installing Nginx from source.

Set up EPEL

Let's begin by installing the EPEL repository.

CentOS 5

If you're using CentOS 5 install the repository with the following command:

sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm

CentOS 6

If you're using CentOS 6 install the repository with the following command:

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

Install nginx

Installing nginx using Yum is now incredibly simple, thanks to EPEL, as it involves one command:

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 DSA signature: NOKEY, key ID 217521f6
Importing GPG key 0x217521F6 "Fedora EPEL <epel@fedoraproject.org>" from /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
Is this ok [y/N]:

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.

This will install any dependencies that Nginx requires and actually incorporates the experimental Perl module. You can read more documentation about this feature as well as many others at the Nginx Community Wiki.

iptables

You may need to open ports in your server's firewall to allow connections to nginx on port 80 (and 443 if you intend to enable SSL).  You can use the instructions in this article to open the required ports.

Start

One odd thing is that Nginx is not started automatically:

sudo /etc/init.d/nginx start

Done

Navigate

Now simply navigate to your IP address:

http://123.45.67.890

and you will see the following welcome screen:

CentOSNginxWelcome.png

Init Scripts

As you would imagine when installing an application with the yum package manager, all init scripts have been created.

However, we need to set up Nginx to start automatically if the server is rebooted:

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 implementing it with a reload or restart.

That's it.

Summary

Using the yum package manager along with the EPEL repository makes the installation of Nginx and associated dependencies very simple indeed.

The only thing to consider is the version disparity between the one offered by yum and the one available via source code.

 



Was this content helpful?




© 2011-2013 Rackspace US, Inc.

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License


See license specifics and DISCLAIMER