How to Install Nginx Mainline Version on CentOS7
The official Nginx release has two versions: stable version and mainline version. The mainline version contains the newest and greatest cutting edge features and as the name implies, the stable version aims to be more stable. If you are a person like me who always like to be on the bleeding edge, then the mainline version of Nginx is your friend.
This tutorial explains how to install Nginx mainline version (Nginx 1.9.12 at the time of this writting) on CentOS7. Nginx 1.9.12 added Huffman encoding of response headers in HTTP/2 and the “worker_cpu_affinity” directive now supports more than 64 CPUs. There are also various bugfixes for OpenSSL, HTTP/2 etc. So Let’s install it on CentOS7!
If you have installed Nginx before, backup your configuration file to the home directory and then remove Nginx.
sudo cp /etc/nginx/nginx.conf /etc/nginx/conf.d/* ~ sudo yum remove nginx
Install Nginx Mainline Version on CentOS7
Download Nginx signing key.
Import it the the rpm keyring.
sudo rpm --import nginx_signing.key
Create a repo file under /etc/yum.repo.d/ directory.
sudo nano /etc/yum.repos.d/nginx.repo
Paster the following lines to this file.
[nginx.org] name=nginx.org repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=1 enabled=1
- Text contained in square brackets  is the alias of this repository.
- name=nginx.org repo specifies the name of this repository
- baseurl= specifies where to download nginx package from
- gpgkcheck=1 means enable checking the integrity of package using GPG signing key once package is downloaded
- enabled=1 means this repository is enabled. If its value is 0, then this repository is disabled
Save and close the file. Now update repositories and install Nginx
sudo yum update && sudo yum install nginx
Start Nginx Web server and enable autostart on system boot with systemctl.
sudo systemctl start nginx sudo systemctl enable nginx
Check Nginx version
[[email protected] ~]$ nginx -v nginx version: nginx/1.9.12
Check Nginx status
sudo systemctl status nginx
● nginx.service - nginx - high performance web server Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled) Active: active (running) since Wed 2016-03-09 03:36:30 EST; 3min 40s ago Docs: http://nginx.org/en/docs/ Main PID: 13665 (nginx) CGroup: /system.slice/nginx.service ├─13665 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf └─13666 nginx: worker process
The official Nginx repository only contains x86_64 packages for CentOS7. If you use 32 bit CentOS 7 server, then you can download Nginx source code and compile it.