5 minute upgrade NGINX 1.12 to 1.17+ on CentOS 7 / RHEL 7

Nginx [engine x] is free and open source high-performance web server. It also acts as a reverse proxy server, as well as. This page shows how to upgrade Nginx server on a CentOS 7.

So here’s the simplest guide ever to upgrade nginx web server from 1.12.2 to 1.17.0

Step 1: Create a backup your nginx directory

We do this well, because we should always have a backup in case things ever go wrong. So this is as simple as doing the following.

mkdir /etc/nginx-backup/
cp -r /etc/nginx/* /etc/nginx-backup/

If you test to see your current version of Nginx you will see the following.

nginx -V
nginx version: nginx/1.12.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled

So now we are going to upgrade nginx to 1.17.0 from the official nginx repository.

Step 2: Configure Nginx repo for CentOS 7

Create a new repo file /etc/yum.repos.d/nginx.repo in your system and add below code as per your operating system and architecture.

For CentOS 7

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/
gpgcheck=0
enabled=1

For RHEL 7

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/rhel/7/$basearch/
gpgcheck=0
enabled=1

Step 3: Update nginx server on CentOS 7

To upgrade nginx server to the latest version, run the following yum command:

yum update

Command output:

base                                                                                                                                                                                 | 3.6 kB  00:00:00     
epel/x86_64/metalink                                                                                                                                                                 |  22 kB  00:00:00     
epel                                                                                                                                                                                 | 5.4 kB  00:00:00     
extras                                                                                                                                                                               | 3.4 kB  00:00:00     
mariadb                                                                                                                                                                              | 2.9 kB  00:00:00     
nginx                                                                                                                                                                                | 2.9 kB  00:00:00     
remi-php73                                                                                                                                                                           | 3.0 kB  00:00:00     
remi-safe                                                                                                                                                                            | 3.0 kB  00:00:00     
updates                                                                                                                                                                              | 3.4 kB  00:00:00     
(1/11): base/7/x86_64/group_gz                                                                                                                                                       | 166 kB  00:00:00     
(2/11): extras/7/x86_64/primary_db                                                                                                                                                   | 205 kB  00:00:00     
(3/11): epel/x86_64/group_gz                                                                                                                                                         |  88 kB  00:00:00     
(4/11): nginx/x86_64/primary_db                                                                                                                                                      | 144 kB  00:00:00     
(5/11): mariadb/primary_db                                                                                                                                                           |  53 kB  00:00:00     
(6/11): remi-php73/primary_db                                                                                                                                                        | 198 kB  00:00:00     
(7/11): epel/x86_64/updateinfo                                                                                                                                                       | 978 kB  00:00:01     
(8/11): remi-safe/primary_db                                                                                                                                                         | 1.6 MB  00:00:00     
(9/11): base/7/x86_64/primary_db                                                                                                                                                     | 6.0 MB  00:00:01     
(10/11): epel/x86_64/primary_db                                                                                                                                                      | 6.8 MB  00:00:01     
(11/11): updates/7/x86_64/primary_db                                                                                                                                                 | 6.4 MB  00:00:01     
Resolving Dependencies
--> Running transaction check
---> Package nginx.x86_64 1:1.12.2-3.el7 will be updated
---> Package nginx.x86_64 1:1.17.0-1.el7.ngx will be an update
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================================================================================================================
 Package                                      Arch                                          Version                                                      Repository                                    Size
============================================================================================================================================================================================================
Updating:
 nginx                                        x86_64                                        1:1.17.0-1.el7.ngx                                           nginx                                        767 k

Transaction Summary
============================================================================================================================================================================================================
Upgrade  1 Package

Total download size: 767 k
Is this ok [y/d/N]: y

Step 4: Find and remove old nginx server version modules

Run command:

rpm -qa | grep nginx
nginx-mod-http-xslt-filter-1.12.2-3.el7.x86_64
nginx-mod-stream-1.12.2-3.el7.x86_64
nginx-1.17.0-1.el7.ngx.x86_64
nginx-filesystem-1.12.2-3.el7.noarch
nginx-mod-http-perl-1.12.2-3.el7.x86_64
nginx-mod-mail-1.12.2-3.el7.x86_64
nginx-mod-http-geoip-1.12.2-3.el7.x86_64
nginx-mod-http-image-filter-1.12.2-3.el7.x86_64
nginx-all-modules-1.12.2-3.el7.noarch

In the output we see two versions 1.12.2 and 1.17.0. The old version of nginx server modules should be removed.
Run command:

yum remove nginx-mod-http-xslt-filter nginx-mod-stream nginx-filesystem nginx-mod-http-perl nginx-mod-mail nginx-mod-mail nginx-mod-http-geoip nginx-mod-http-image-filter nginx-all-modules

Command output:

Resolving Dependencies
--> Running transaction check
---> Package nginx-all-modules.noarch 1:1.12.2-3.el7 will be erased
---> Package nginx-filesystem.noarch 1:1.12.2-3.el7 will be erased
---> Package nginx-mod-http-geoip.x86_64 1:1.12.2-3.el7 will be erased
---> Package nginx-mod-http-image-filter.x86_64 1:1.12.2-3.el7 will be erased
---> Package nginx-mod-http-perl.x86_64 1:1.12.2-3.el7 will be erased
---> Package nginx-mod-http-xslt-filter.x86_64 1:1.12.2-3.el7 will be erased
---> Package nginx-mod-mail.x86_64 1:1.12.2-3.el7 will be erased
---> Package nginx-mod-stream.x86_64 1:1.12.2-3.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================================================================================================================
 Package                                                        Arch                                      Version                                            Repository                                Size
============================================================================================================================================================================================================
Removing:
 nginx-all-modules                                              noarch                                    1:1.12.2-3.el7                                     @epel                                    0.0  
 nginx-filesystem                                               noarch                                    1:1.12.2-3.el7                                     @epel                                    0.0  
 nginx-mod-http-geoip                                           x86_64                                    1:1.12.2-3.el7                                     @epel                                     21 k
 nginx-mod-http-image-filter                                    x86_64                                    1:1.12.2-3.el7                                     @epel                                     24 k
 nginx-mod-http-perl                                            x86_64                                    1:1.12.2-3.el7                                     @epel                                     54 k
 nginx-mod-http-xslt-filter                                     x86_64                                    1:1.12.2-3.el7                                     @epel                                     24 k
 nginx-mod-mail                                                 x86_64                                    1:1.12.2-3.el7                                     @epel                                     99 k
 nginx-mod-stream                                               x86_64                                    1:1.12.2-3.el7                                     @epel                                    157 k

Transaction Summary
============================================================================================================================================================================================================
Remove  8 Packages

Installed size: 380 k
Is this ok [y/N]: y

Step 5: Install latest nginx server modules

Run comand:

yum install nginx-module-xslt nginx-module-perl nginx-module-geoip nginx-module-image-filter

Command output:

base                                                                                                                                                                                 | 3.6 kB  00:00:00     
epel/x86_64/metalink                                                                                                                                                                 |  30 kB  00:00:00     
epel                                                                                                                                                                                 | 5.3 kB  00:00:00     
extras                                                                                                                                                                               | 3.4 kB  00:00:00     
mariadb                                                                                                                                                                              | 2.9 kB  00:00:00     
nginx                                                                                                                                                                                | 2.9 kB  00:00:00     
remi-php73                                                                                                                                                                           | 3.0 kB  00:00:00     
remi-safe                                                                                                                                                                            | 3.0 kB  00:00:00     
updates                                                                                                                                                                              | 3.4 kB  00:00:00     
(1/11): base/7/x86_64/group_gz                                                                                                                                                       | 166 kB  00:00:00     
(2/11): extras/7/x86_64/primary_db                                                                                                                                                   | 205 kB  00:00:00     
(3/11): epel/x86_64/group_gz                                                                                                                                                         |  88 kB  00:00:00     
(4/11): nginx/x86_64/primary_db                                                                                                                                                      | 147 kB  00:00:00     
(5/11): epel/x86_64/updateinfo                                                                                                                                                       | 977 kB  00:00:00     
(6/11): mariadb/primary_db                                                                                                                                                           |  53 kB  00:00:00     
(7/11): remi-php73/primary_db                                                                                                                                                        | 199 kB  00:00:00     
(8/11): remi-safe/primary_db                                                                                                                                                         | 1.6 MB  00:00:00     
(9/11): base/7/x86_64/primary_db                                                                                                                                                     | 6.0 MB  00:00:01     
(10/11): epel/x86_64/primary_db                                                                                                                                                      | 6.8 MB  00:00:02     
(11/11): updates/7/x86_64/primary_db                                                                                                                                                 | 6.4 MB  00:00:01     
Resolving Dependencies
--> Running transaction check
---> Package nginx-module-geoip.x86_64 1:1.17.1-1.el7.ngx will be installed
---> Package nginx-module-image-filter.x86_64 1:1.17.1-1.el7.ngx will be installed
---> Package nginx-module-perl.x86_64 1:1.17.1-1.el7.ngx will be installed
---> Package nginx-module-xslt.x86_64 1:1.17.1-1.el7.ngx will be installed
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================================================================================================================
 Package                                                     Arch                                     Version                                                 Repository                               Size
============================================================================================================================================================================================================
Installing:
 nginx-module-geoip                                          x86_64                                   1:1.17.1-1.el7.ngx                                      nginx                                    18 k
 nginx-module-image-filter                                   x86_64                                   1:1.17.1-1.el7.ngx                                      nginx                                    21 k
 nginx-module-perl                                           x86_64                                   1:1.17.1-1.el7.ngx                                      nginx                                    35 k
 nginx-module-xslt                                           x86_64                                   1:1.17.1-1.el7.ngx                                      nginx                                    19 k

Transaction Summary
============================================================================================================================================================================================================
Install  4 Packages

Total download size: 92 k
Installed size: 276 k
Is this ok [y/d/N]: y

Step 6: Restart nginx server

Restart Nginx command

systemctl restart nginx

Leave a Reply

Your email address will not be published. Required fields are marked *