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

6 Replies to “5 minute upgrade NGINX 1.12 to 1.17+ on CentOS 7 / RHEL 7”

    1. Thanks for your feedback. I have added information on how to install missing modules from repository. Run a command and see all available modules
      yum search nginx | grep nginx-module

  1. I’ve done a little bit of extra homework on translating the packages from what’s installed by EPEL to what’s in the Nginx repo to ease the minds of other people wondering why not all of the modules appear to get reinstalled.-

    # Trash from EPEL
    – `nginx-all-modules`: This is described as a “temporary” meta package that simply installs all available modules “to ease the upgrade path”. This means that you might not actually _need_ all of the modules you have installed, but you’re stuck with them unless you can say for certain that you don’t. EPEL’s `nginx` package lists this as a dependency.
    – `nginx-filesystem`: “The basic directory layout for the Nginx server” so 99.999% inconsequential. The directories are still there, and your existing config file should reference everything properly. Also specified as a dependency by EPEL’s `nginx` package.

    # Core Modules
    Both `mail` and `stream` modules are built into the Nginx repo’s `nginx` package, so you don’t need a separate package.

    # Modules that you [maybe] need from the Nginx repo
    – `nginx-module-geoip`
    – `nginx-module-perl`
    – `nginx-module-xslt`
    – `nginx-module-image-filter`

  2. Hi Wade Rossmann,

    version 1.17 is not stable version, please update the nginx.repo file as:

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

    Then try to remove all nginx package by following commands:
    # yum remove nginx nginx-module-xslt nginx-module-perl nginx-module-geoip nginx-module-image-filter

    Then clean the yum cache by:
    # yum clean all

    Finally, try to install nginx and all modules again:
    # yum install nginx
    # yum install -y 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

  3. Finding “old” modules via
    rpm -qa | grep nginx
    and gettig rid of them via yum remove can be dangerous.
    I accidentally removed vesta-nginx thinking it was an old version, and completely crashed my webserver, and had a horrible time trying to reinstall VestaCP (it hates to be reinstalled when a username already exists).
    Be careful.

    1. Hi, you should not delete anything related to your server administration system / panel. In this case VestaCP (vesta-nginx-0.9.8-25.x86_64)

Leave a Reply

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