Install Nginx on CentOS 6 and Amazon Linux AMI

This how to guide details the process to install Nginx on CentOS 6 and Amazon Linux AMI.

Nginx (pronounced engine-x) is gaining popularity as an alternative to using Apache. I won’t weigh in on the argument as to which is better, as they each have their own strengths and weaknesses which I’m sure there are plenty of other documents available on the internet which discuss these at great length. Instead I will show you a simple way to get up and running with Nginx on CentOS or Amazon Linux AMI.

Step 1: Add the EPEL Repository

CentOS doesn’t have Nginx available in it’s base repository so we have to add the EPEL repository. Thankfully this is really easy.
64bit run:

32bit run:

Installing the EPEL RPM will also automatically enable the EPEL repository so nothing more is needed to be done. If the URL I used in my example doesn’t work, it may be because a new version has been released. You can check for the latest EPEL release rpm here: http://dl.fedoraproject.org/pub/epel/6/x86_64/repoview/epel-release.html
http://dl.fedoraproject.org/pub/epel/6/i386/repoview/epel-release.html

Step 2: Install Nginx

Now that the EPEL repository has been installed and enabled, time to install Nginx:

Step 3: Finishing Up

Now that Nginx is installed, lets start, test it and have it launch automatically when the system boots.

Start Nginx:

Configure Nginx to start with system boot:

Test it:
Assuming your firewall allows inbound port 80, you should be able to open up a web browser and point it to the IP or hostname of the server and see the default Nginx homepage. If iptables is blocking port 80 (which is on by default in CentOS 6) you can run the following command to allow inbound http connections.

The above iptables command is just a quick and dirty way of getting port 80 open, I would suggest spending more time and developing a more thorough firewall rule set.

  2 comments

  1. Adam McArthur   •  

    Thanks for sharing this Andrew!

    I was stuck on this for ages because I didn’t realise you had to add the EPEL repository first.

  2. Pingback: Setting up AWS for WordPress with EC2, RDS, Nginx, HHVM - Part Two - Hosting WordPress on AWS Tutorial - Wordpress, Websites & Email Help

Leave a Reply

Your email address will not be published. Required fields are marked *


+ 5 = six

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">