Nginx Basics – How to Install Nginx on RHEL and Debian based Operating Systems


Nginx was best known as the go-to event based web server, as it uses threads instead of processes like the popular Apache web server does. Under high loads, such as 100,000 simultaneous connection requests, threads provide much more efficient RAM allocation, particularly for resource limited hardware.

This all changed with the release of Apache 2.4, which has an event based model with Worker MPM. Why choose Nginx over Apache today? You might be familiar with some of the following companies that utilize Nginx:

  • Netflix
  • Hulu
  • Pinterest
  • CloudFlare
  • WordPress.com
  • Github
  • RightScale

All of these are very visible sites that receive incredibly high amounts of traffic daily, kept running fast thanks in part to Nginx and the server’s low resource consumption.

This guide will have everything you need to get Nginx installed on your new RHEL or Debian based Linux Cloud Server here at Rackspace. Feel free to copy/paste everything after the ":" for your convenience.

Installation on RHEL based OS

Install Nginx on RHEL 6.x with the following steps:

  1. Check for system updates: sudo yum update
  2. Create file to discover repository URL (Using VI text editor in this example):
    sudo vi /etc/yum.repos.d/nginx.repo
  3. Enter write mode: i
  4. Paste the following configurations:
    [nginx]
    name=nginx repo
    baseurl=http://nginx.org/packages/rhel/6/$basearch/
    gpgcheck=0
    enabled=1
  5. Press Esc to return to read mode.
  6. Press Ctrl + X to save and quit the file.
  7. Install the newly added repo:
    sudo yum install nginx.x86_64
  8. Start the service:
    sudo service nginx start
  9. Have the service start upon reboot:
    sudo chkconfig nginx on
  10. You’re done! You can verify the service is now running on default port 80 by running the following:
    netstat –tnlp

Note: If you’re running RHEL 5.x instead, simply replace the configuration line

baseurl=http://nginx.org/packages/rhel/6/$basearch/

with:

baseurl=http://nginx.org/packages/rhel/5/$basearch/

Install Nginx on CentOS 6.x with the following steps:

  1. Check for system updates:
    sudo yum update
  2. Create file to discover repository URL (Using VI text editor in this example):
    sudo vi /etc/yum.repos.d/nginx.repo
  3. Enter write mode: i
  4. Paste the following configurations:
    [nginx]
    name=nginx repo
    baseurl=http://nginx.org/packages/centos/6/$basearch/
    gpgcheck=0
    enabled=1
  5. Press Esc to return to read mode
  6. Press ctrl+x to save and quit thefile.
  7. Install the newly added repo:
    sudo yum install nginx.x86_64
  8. Start the service:
    sudo service nginx start
  9. Set the service start upon reboot:
    sudo chkconfig nginx on
  10. You’re done! You can verify the service is now running on default port 80 by running the following command:
    netstat –tnlp

Note : If you’re running CentOS 5.x instead, simply replace the configuration line:

baseurl=http://nginx.org/packages/centos/6/$basearch/

with

baseurl=http://nginx.org/packages/centos/5/$basearch/

instead.

Installation on Debian based OS

Install Nginx on Debian 7.x with the following steps:

  1. Check for system updates:
    sudo apt-get update
  2. Create file to discover repository URL (Using nano text editor in this example):
    sudo nano /etc/apt/sources.list
  3. Paste the following configurations:
    deb http://nginx.org/packages/debian/ squeeze nginx
    deb-src http://nginx.org/packages/debian/ squeeze nginx 
  4. Press Ctrl+x to save and quit the file, press y to overwrite, then press Enter to confirm save.
  5. Install the newly added repo:
    sudo apt-get install nginx
  6. Start the service:
    sudo service nginx start
  7. Have the service start upon reboot:
    sudo /usr/sbin/update-rc.d -f nginx defaults
  8. You’re done! You can verify the service is now running on default port 80 by running the following command:
    netstat –tnlp

Note: If you’re running Debian 6.x instead, simply replace the configuration lines from:

deb http://nginx.org/packages/debian/ wheezy nginx
deb-src http://nginx.org/packages/debian/ wheezy nginx

to:

deb http://nginx.org/packages/debian/ squeeze nginx
deb-src http://nginx.org/packages/debian/ squeeze nginx

Install Nginx on Ubuntu 14.04 LTS Trusty Tahr with the following steps:

  1. Check for system updates:
    sudo apt-get update
  2. Create file to discover repository URL (Using nano text editor in this example):
    sudo nano /etc/apt/sources.list
  3. Paste the following configurations:
    deb http://nginx.org/packages/ubuntu/ trusty nginx
    deb-src http://nginx.org/packages/ubuntu/ trusty nginx
  4. Press ctrl+x to save and quit the file, press y to overwrite, then press Enter to confirm save.
  5. Install the newly added repo:
    sudo apt-get install nginx
  6. Start the service:
    sudo service nginx start
  7. Set the service start upon reboot:
    sudo /usr/sbin/update-rc.d -f nginx defaults

    (This should be set as default already.)

  8. You’re done! You can verify the service is now running on default port 80 by running the following command:
    netstat –tnlp

Note : If you’re running Ubuntu 12.04 Precise Pangolin instead, simply replace the configuration lines from:

deb http://nginx.org/packages/ubuntu/ trusty nginx
deb-src http://nginx.org/packages/ubuntu/ trusty nginx

To:

deb http://nginx.org/packages/ubuntu/ precise nginx
deb-src http://nginx.org/packages/ubuntu/ precise nginx


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