Nginx Basics – Install Nginx on Red Hat Enterprise Linux and Debian based OSs


Nginx was best known as the go-to event-based web server because 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.

All that changed with the release of Apache 2.4, which has an event-based model with Worker MPM. So why should you choose Nginx over Apache today? You might be familiar with some of the following companies that use Nginx:

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

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

This guide provides everything you need to know to install Nginx on your new Red Hat Enterprise Linux or Debian based Linux cloud server at Rackspace. You can copy the code samples.

Install Nginx on Red Hat based OSs

This section provides the following instructions:

  • Install Nginx on Red Hat 5.x and 6.x
  • Install Nginx on CentOS 5.x and 6.x

Install Nginx on Red Hat 5.x and 6.x

  1. Check for system updates:
    sudo yum update
  2. Create a file to discover the repository URL (the following example uses the vi text editor):
    sudo vi /etc/yum.repos.d/nginx.repo
  3. Enter write mode by typing i.
  4. Enter the following configurations:
    [nginx]
    name=nginx repo
    baseurl=http://nginx.org/packages/rhel/6/$basearch/
    gpgcheck=0
    enabled=1

    Note: If you are running Red Hat 5.x instead, replace the baseurl configuration line with the following line:

    baseurl=http://nginx.org/packages/rhel/5/$basearch/
  5. Press Esc to return to read mode.
  6. Press Ctrl+X to save and quit the file.
  7. Install the newly added repository:
    sudo yum install nginx.x86_64
  8. Start the service:
    sudo service nginx start
  9. Have the service start on reboot:
    sudo chkconfig nginx on
  10. Verify that the service is now running on default port 80 by running the following command:
    netstat –tnlp

Install Nginx on CentOS 5.x and 6.x

  1. Check for system updates:
    sudo yum update
  2. Create a file to discover the repository URL (the following example uses the vi text editor):
    sudo vi /etc/yum.repos.d/nginx.repo
  3. Enter write mode by typing i.
  4. Enter the following configurations:
    [nginx]
    name=nginx repo
    baseurl=http://nginx.org/packages/centos/6/$basearch/
    gpgcheck=0
    enabled=1

    Note: If you are running CentOS 5.x instead, replace the baseurl configuration line with the following line:

    baseurl=http://nginx.org/packages/centos/5/$basearch/
  5. Press Esc to return to read mode.
  6. Press Ctrl+X to save and quit the file.
  7. Install the newly added repository:
    sudo yum install nginx.x86_64
  8. Start the service:
    sudo service nginx start
  9. Set the service start on reboot:
    sudo chkconfig nginx on
  10. Verify that the service is now running on default port 80 by running the following command:
    netstat –tnlp

Install Nginx on Debian based OSs

This section provides the following instructions:

  • Install Nginx on Debian 6.x and 7.x
  • Install Nginx on Ubuntu 14.04 LTS Trusty Tahr and 12.04 Precise Pangolin

Install Nginx on Debian 6.x and 7.x

  1. Check for system updates:
    sudo apt-get update
  2. Create a file to discover the repository URL (the following example uses the nano text editor):
    sudo nano /etc/apt/sources.list
  3. Enter the following configurations:
    deb http://nginx.org/packages/debian/ wheezy nginx
    deb-src http://nginx.org/packages/debian/ wheezy nginx 

    Note: If you are running Debian 6.x instead, replace these configuration lines with the following lines:

    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, and then press Enter to confirm the save.
  5. Install the newly added repository:
    sudo apt-get install nginx
  6. Start the service:
    sudo service nginx start
  7. Have the service start on reboot:
    sudo /usr/sbin/update-rc.d -f nginx defaults
  8. Verify that the service is now running on default port 80 by running the following command:
    netstat –tnlp

Install Nginx on Ubuntu 14.04 LTS Trusty Tahr and 12.04 Precise Pangolin

  1. Check for system updates:
    sudo apt-get update
  2. Create a file to discover the repository URL (the following example uses the nano text editor):
    sudo nano /etc/apt/sources.list
  3. Enter the following configurations:
    deb http://nginx.org/packages/ubuntu/ trusty nginx
    deb-src http://nginx.org/packages/ubuntu/ trusty nginx

    Note: If you are running Ubuntu 12.04 Precise Pangolin instead, replace these configuration lines with the following lines:

    deb http://nginx.org/packages/ubuntu/ precise nginx
    deb-src http://nginx.org/packages/ubuntu/ precise nginx
  4. Press Ctrl+X to save and quit the file, press y to overwrite, and then press Enter to confirm the save.
  5. Install the newly added repository:
    sudo apt-get install nginx
  6. Start the service:
    sudo service nginx start
  7. Set the service start on reboot. (This should be set as the default already.)
    sudo /usr/sbin/update-rc.d -f nginx defaults
  8. Verify that the service is now running on default port 80 by running the following command:
    netstat –tnlp


Was this content helpful?




© 2015 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