Nginx / Server Setup

How to install nginx on RHEL 7 / CentOS 7 properly

by , , revisited on


We have by far the largest RPM repository with dynamic stable NGINX modules and VMODs for Varnish 4.1 and 6.0 LTS. If you want to install nginx, Varnish and lots of useful modules for them, this is your one stop repository to get all performance related software.
You have to maintain an active subscription in order to be able to use the repository!

The Internet is full of wrong advice everywhere. Unfortunately, first results in Google tend to lead you to the worst advice of compiling NGINX from source to avail of features like ALPN or integrating some module. See my post on [where compilation is wrong][https://www.getpagespeed.com/server-setup/where-compilation-went-wrong] to realize why compilation should be absolutely avoided.

Follow these instructions on how to install the latest stable NGINX web server in RHEL 7 / CentOS 7 server.

Step 1. Prepare your system

First things first. You have to upgrade your RHEL / CentOS 7 to the latest release:

sudo yum -y upgrade

Next, decide on the repository to fetch NGINX from:

Step 2. Setup RPM repository

Option 1. Install latest stable NGINX from nginx.org repository

To add this repository, import NGINX package signing key and install release package which contains the YUM repository file.

sudo rpm --import https://nginx.org/keys/nginx_signing.key 
sudo yum -y install http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

NGINX may be present in other repositories which are found on your system. Popular EPEL repository has NGINX as well. So let’s make sure that the NGINX version from the configured repository will have priority over other versions.

Install priorities yum plugin and adjust NGINX repository priority:

sudo yum -y install yum-plugin-priorities
echo 'priority=1' | sudo tee -a /etc/yum.repos.d/nginx.repo

Now yum will prefer to install NGINX from the official repository.

Option 2. Install latest stable NGINX from GetPageSpeed (extras.getpagespeed.com) repository

Our CDN powered repository builds on exact same binaries released by official nginx.org website.

Recommended: It can work as a standalone base for installing NGINX because it has copies of stable NGINX builds. In that case, only install this repository.

Alternatively, GetPageSpeed repository can be used to extend the official (nginx.org) repository with many NGINX modules. This way you can install the base nginx package from the official repository, while all the amazing modules will be fetched from GetPageSpeed. In that case, you would install both repositories.

To setup GetPageSpeed repository, run

sudo yum -y install https://extras.getpagespeed.com/release-el7-latest.rpm

Step 3. Install NGINX

Install NGINX with:

sudo yum -y install nginx

Run NGINX

Now we are ready to run NGINX:

sudo systemctl start nginx

And don’t forget to enable it at boot time:

sudo systemctl enable nginx

Also published on Medium.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.