How to install nginx on CentOS 7 properly

Danila Vershinin
Apr 7, 2018 · 2 min read

These instructions aim to provide proper and the only correct way to install nginx web server on CentOS 7.

Prepare your system

First things first. You have to upgrade your CentOS 7 to latest release because nginx natively supports CentOS 7 >= 7.4:

yum -y upgrade

Add stable nginx repository

Now that we have at least CentOS 7.4, let’s install nginx repository to our system. We import nginx package signing key and install release package which contains the nginx yum repository file.

rpm --import 
yum -y install

As of this writing, EPEL repository has nginx package 1.12.2-2.el7 whereas nginx latest package is 1.12.2-1.el7_4.ngx. The actual version number is the same, but release number (-2 vs -1 in package names) is different. So if we proceed with installation, yum would install nginx from EPEL.

The nginx packages by EPEL have entirely different structure and we want stable nginx server which is packaged and maintained by its creators.

So let’s make sure that the native nginx repository has priority over the others.

Install priorities yum plugin and adjust nginx repository priority:

yum -y install yum-plugin-priorities
echo 'priority=1' >> /etc/yum.repos.d/nginx.repo

Now yum will prefer to install nginx from stable nginx repository. Finalise your nginx setup with:

yum -y install nginx

Originally published at GetPageSpeed.

Danila Vershinin

Written by

Performance Oriented DevOp

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade