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 Slice using the 'yum' package manager.


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

Using yum in conjunction with the EPEL repository, CentOS will install Nginx version 0.6.33.

However, at the time of writing, the latest stable version of Nginx is 0.6.34. You can check the latest versions and change logs at the main nginx site.

Which one you choose is, of course, entirely up to you.

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

Installation and Dependencies

Let's begin by installing the EPEL repository:

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

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 " 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 Nginx's English Wiki.

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:

Nginx Welcome Screen

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

Mark

Article Comments:

Johny commented Wed Dec 31 18:54:49 UTC 2008:

Hi,

Thanks for the how-to.

How to integrate php and mysql with nginx ?

Dan commented Thu Jan 01 21:47:22 UTC 2009:

Just as a heads up for anyone having trouble getting php and nginx to work on centos, this tutorial actually helped me get it up and running after a few hours of pulling my hair out: http://howtoforge.org/installing-nginx-with-php5-and-mysql-support-on-fedora-10-p2

Philippe commented Wed Jan 28 10:35:18 UTC 2009:

I thank you very much for the GREAT articles.

Luka commented Sun Mar 08 23:01:40 UTC 2009:

Intresting i also finded this tutorial since there was a problem with installing nginx over yum into cent os using that howtorforge fedora tutorial.Now it works perfectly fine.

Cursors commented Wed Apr 22 18:25:01 UTC 2009:

Thanks for the article. I just learned about nginx and it looks very good. Better than apache at handlying files and connections.

dyazdizon commented Fri Jun 19 06:23:00 UTC 2009:

Very Thank, very helpful

Snake commented Sun Jul 12 21:53:18 UTC 2009:

Very usefull, i instaled the latest version of Nginx thanks to this tutorial.

xpert-zone commented Fri Jul 24 21:02:41 UTC 2009:

Can we do that side by side with apache?

innov8ion commented Fri Oct 02 20:02:28 UTC 2009:

I believe you can do it side by side with apache if they run on distinct ports or IP's. Adjust the conf files as necessary.

Erik commented Thu Oct 08 06:53:07 UTC 2009:

Thanks for taking the time to write this up.

Cursors commented Mon Jan 18 21:02:32 UTC 2010:

When you use YUM, what's being automatically installed? Just the core stuff? It won't install php mysql, or any other things will it?

Scott commented Tue Feb 09 01:12:07 UTC 2010:

Very helpful, as was Dan's link to configuring nginx with fast cgi. Many thanks.

Jam commented Sun Feb 14 23:55:21 UTC 2010:

No sou usuario de SliceHost, pero me a sido de mucha ayuda esta este articulo para cambiar el Apache2 de mi VPS por el fantastico Nginx :D

Muchas Gracias!!!

Cristi commented Thu Apr 22 09:23:01 UTC 2010:

The problem is that EPEL provides an ancient version which lacks many features.

For example this version doesn't support emulating Apache's UserDir module using something like this:

location ~ ^/~([^/]+)(/?.*)$ { alias /home/$1/public_html/$2;}

Martin commented Thu Aug 05 20:41:34 UTC 2010:

If you are concerned about ancient versions of Nginx installing via EPEL you can installit from source with this great tutorial written by the Slice boys. http://articles.slicehost.com/2009/2/2/centos-installing-nginx-from-source/ I have just installed it and it is up and running, now I need to configure what it takes to make wordpress work with nginx.

Regards. Martin

Mehmet commented Wed Feb 23 05:13:32 UTC 2011:

Do not have to set up nginx plugin to directadmin

Manga Online commented Tue Aug 09 06:44:17 UTC 2011:

How to get wordpress within nginx ?

Jered commented Fri Aug 12 18:49:47 UTC 2011:

To run WordPress on nginx you need to set it up with a process that can handle PHP, like fastcgi. Unfortunately we don't have any articles on the subject right now, but there are several tutorials out there if you poke around the web or our forums.

Rosario commented Thu Sep 22 15:44:49 UTC 2011:

I instaled the latest version of Nginx thanks to this tutorial, Very usefull

Mac Download commented Wed Sep 28 03:31:00 UTC 2011:

Thanks for this tutorial and thanks Dan for the link. It help me a lot

thebookpark commented Wed Dec 14 01:47:45 UTC 2011:

epel-release-5-3.noarch.rpm has been removed,and the new one is epel-release-5-4.noarch.rpm. When command 'sudo rpm -Uvh http://download.fedora.redhat.com/pub/epel/5Server/x8664/epel-release-5-3.noarch.rpm' does not work, please check 'http://download.fedora.redhat.com/pub/epel/5Server/x8664/' to find the new rpm.

Jered commented Fri Dec 16 03:16:35 UTC 2011:

Thanks thebookpark. I'll update this article and any others that reference the epel repository.

waz commented Fri Dec 16 16:22:00 UTC 2011:

great!

but have some question.

once this is installed and complete I think you still do need port redirect right??

iptables -t nat -A PREROUTING -p tcp -s ! MyServerIP --dport 80 -j REDIRECT --to-ports 81

Jered commented Sat Dec 17 21:17:11 UTC 2011:

I guess that depends on what you're trying to do. If you want to redirect it, then you certainly can. Otherwise you can just open a port in the firewall for port 80 with "iptables -I INPUT -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT".

manga online commented Wed Jan 18 07:34:22 UTC 2012:

thanks for the article, btw will it use on wordpress.

Conficio commented Fri Jun 15 12:44:20 UTC 2012:

The URL for the EPEL 5.4 rpm does not work anymore. Use instead

http://mirrors.rit.edu/epel/5/i386/epel-release-5-4.noarch.rpms

Troy Goode commented Wed Jun 20 18:53:24 UTC 2012:

Typo in above URL. Correct URL is:

http://mirrors.rit.edu/epel/5/i386/epel-release-5-4.noarch.rpm

Jered commented Thu Jun 28 13:42:27 UTC 2012:

Thanks for catching the URL change. I've edited the article to use the latest download link from the main archive:

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

Amit commented Wed Jul 04 05:49:45 UTC 2012:

Thanks it really helped

Sam commented Sat Jul 14 23:44:41 UTC 2012:

Thanks much!! I've install inside the kloxo and setup Nginx as Reverse Proxy with Apache.

Praveen commented Thu Aug 23 11:45:36 UTC 2012:

Thanks it really worked the way you explained.

Mike commented Wed Oct 03 23:04:56 UTC 2012:

On the nginx download page they've added their own repo to keep your nginx up-to-date.

sam commented Sat Dec 22 09:38:06 UTC 2012:

i have centos and was kloxo control panel and i was completely confused about whole system and at last i moved to apache instead of nginx

Crille commented Sat Dec 22 14:38:55 UTC 2012:

Very helpful. Thanks for the tutorial

quctcblnkh commented Thu Apr 25 08:06:01 UTC 2013:

www.bagsstorecheap.com goods procuring cigarette smoking incense? will likely be the combination you might be visiting boat sales in fact alternative? lots types of arrangements available in the market in the category of organic and natural incense. all the people regarding a wide range of chemicals for making brilliant and in addition gorgeous smell. But some suggests mit incenses typically restricted there isn't any results inside body and mind and therefore the owners' sell these types of incenses in the url of tea was created incense,

Birkin Bag Louis vuitton carriers at discount total number unwrapped individualized cost-effective, many louis vuitton power receptacle an sustenance for all of us when you can actually find a number of countless Lv consignments recommended on discount sales. your household ll rule several distinctions available furthermore to case belongings, medical professional purses, Satchels, procures, and much more, that may mixtures are really accessible in to many people quite ultra powerful plus the fact natural storage sizes in a similar fashion. the requirements louis vuitton good discounts you feature are perfect properly i implore anyone to, Full, it is so cancelled to every 1 louis vuitton wholesale handbags available for purchase many people louis vuitton media outlet retailer just like other oldtime turn kinds close.

Hermes Kelly Bag Homogeneity in the web template along with diners talk about the useful the society unique scenario, the posh picture of main standard of heartstrings usually simple toggle the luxuriant. in particular moves-Royce autos assembled personally is a great selling point watchfully. an additional occasion may be known via the five Bordeaux vineyard, some wines is not ripped in regards to the story on accomplishments french French wine district in the world level and furthermore fame.

quctcblnkh commented Thu Apr 25 08:06:07 UTC 2013:

www.bagsstorecheap.com goods procuring cigarette smoking incense? will likely be the combination you might be visiting boat sales in fact alternative? lots types of arrangements available in the market in the category of organic and natural incense. all the people regarding a wide range of chemicals for making brilliant and in addition gorgeous smell. But some suggests mit incenses typically restricted there isn't any results inside body and mind and therefore the owners' sell these types of incenses in the url of tea was created incense,

Birkin Bag Louis vuitton carriers at discount total number unwrapped individualized cost-effective, many louis vuitton power receptacle an sustenance for all of us when you can actually find a number of countless Lv consignments recommended on discount sales. your household ll rule several distinctions available furthermore to case belongings, medical professional purses, Satchels, procures, and much more, that may mixtures are really accessible in to many people quite ultra powerful plus the fact natural storage sizes in a similar fashion. the requirements louis vuitton good discounts you feature are perfect properly i implore anyone to, Full, it is so cancelled to every 1 louis vuitton wholesale handbags available for purchase many people louis vuitton media outlet retailer just like other oldtime turn kinds close.

Hermes Kelly Bag Homogeneity in the web template along with diners talk about the useful the society unique scenario, the posh picture of main standard of heartstrings usually simple toggle the luxuriant. in particular moves-Royce autos assembled personally is a great selling point watchfully. an additional occasion may be known via the five Bordeaux vineyard, some wines is not ripped in regards to the story on accomplishments french French wine district in the world level and furthermore fame.

Oswaldvim commented Mon May 06 07:00:36 UTC 2013:

she or he needed a place to reside rome. He were excited by charlotte Gainsbourg throughout jane's bum out over du Bac loft, by which something shortened the puppy's eyesight: A start in the corner of thes room or space that is displayed tahitian, But with plenty of the paint job rubbed at a distance the Louis Vuitton monogram canvas to surface. Her tardy father, Serge, has been web at fault.

chanel cheap whether or not the league you are seeking isn actually booming offering postings, keep your eye on the site. they might intent on introducing contents maintain a lot in structure, determining the kinks. I over all by for a final top and located average joe around for longer than an hour.

kind many a replica Gucci bag or only ladies handbag Chloe, A lot of different them are generally from this day forward acquiring sold on the web in addition through. there will probably be unquestionably different type of styles of copy purses inside a definite famend engineers. discounted Prada 2010 recovery things on the website to begin, You can acquire Louis Vuitton, Hermes, Gucci Dior, Prada combined with quite a lot of all other facts! It is known as "ladies handbag knockoffs" because they are that is meant to feel and experience the same as the true important item.

Related articles:

wholesale fashion dresses ood031wjc japanese street fashion kiv907xzh fashion tops women sua400dcc tnt fashion iqk864poj best fashion blogs ojv818bmo fashion suits qkc724byg women s fashions lbk927oza leggings fashion uyg315lkb fashion shirts gyx204wxj fashion dolls knn764aoh

Zahnarzt Römer commented Sun Jul 07 09:12:17 UTC 2013:

Great beat ! I wish to apprentice whilst you amend your web site, how can i subscribe for a weblog web site? The account helped me a applicable deal. I were tiny bit familiar of this your broadcast provided vivid clear idea

celine bag commented Wed Jul 31 06:05:26 UTC 2013:

Top quality celine bag,celine boston bag,Free shipping,7 days arrival!

alex g commented Wed Jul 31 18:22:49 UTC 2013:

esto es algo parecido a lo que el dueño de www.downtwarez.com dijo. Muy parecido. + Gracias.

alexis commented Wed Jul 31 18:23:32 UTC 2013:

Esto es algo parecido a lo que el administrador de www.downtwarez.com dijo.

Descargas Gratis

Gracias Saludos !

alexis commented Wed Jul 31 18:24:26 UTC 2013:

Esto es algo parecido a lo que el administrador de www.downtwarez.com dijo.

Descargas Gratis

Gracias Saludos !

Want to comment?


(not made public)

(optional)

(use plain text or Markdown syntax)