Задача: Проработать обновление пакета nginx на Ubuntu 18.04 Server

По дефолту из дефолтных репозитариев Ubuntu 18.04 Server ставится версия nginx:

ekzorchik@srv-bionic:~$ lsb_release -a

No LSB modules are available.

Distributor ID: Ubuntu

Description:    Ubuntu 18.04.6 LTS

Release:        18.04

Codename:       bionic

ekzorchik@srv-bionic:~$

ekzorchik@srv-bionic:~$ apt-cache show nginx | grep Version

Version: 1.14.0-0ubuntu1.11

Version: 1.14.0-0ubuntu1

ekzorchik@srv-bionic:~$

В виду того что до версии nginx < 1.17.7 есть уязвимость раскрытия информации, я задался целью как и что нужно сделать дабы произвести обновление до самой последней версии и жаль что она уже будет не в рамках дефолтных репозитариев.

Как гласит описание: Данные версии подвержены уязвимости, связанной с раскрытием информации. Злоумышленники могут воспользоваться этой уязвимостью для получения информации     с сервера, что может повлиять на безопасность системы.

На заметку: Текущая заметка обкатывается на тестовой системе дабы после, когда все шаги будут отрепетированы произвести обновление на боевой системе.

ekzorchik@srv-bionic:~$ sudo rm -Rf /var/lib/apt/lists

ekzorchik@srv-bionic:~$ sudo apt-get update && sudo apt-get upgrade -y

ekzorchik@srv-bionic:~$ sudo apt-get install nginx -y

ekzorchik@srv-bionic:~$ dpkg -l | grep nginx

ii  libnginx-mod-http-geoip                1.14.0-0ubuntu1.11                              amd64        GeoIP HTTP module for Nginx

ii  libnginx-mod-http-image-filter         1.14.0-0ubuntu1.11                              amd64        HTTP image filter module for Nginx

ii  libnginx-mod-http-xslt-filter          1.14.0-0ubuntu1.11                              amd64        XSLT Transformation module for Nginx

ii  libnginx-mod-mail                      1.14.0-0ubuntu1.11                              amd64        Mail module for Nginx

ii  libnginx-mod-stream                    1.14.0-0ubuntu1.11                              amd64        Stream module for Nginx

ii  nginx                                  1.14.0-0ubuntu1.11                              all          small, powerful, scalable web/proxy server

ii  nginx-common                           1.14.0-0ubuntu1.11                              all          small, powerful, scalable web/proxy server - common files

ii  nginx-core                             1.14.0-0ubuntu1.11                              amd64        nginx web/proxy server (standard version)

ekzorchik@srv-bionic:~$

Приступаю к процедуре обновления:

ekzorchik@srv-bionic:~$ sudo nano /etc/apt/sources.list.d/nginx.list

deb [arch=amd64] http://nginx.org/packages/mainline/ubuntu/ bionic nginx

ekzorchik@srv-bionic:~$ wget http://nginx.org/keys/nginx_signing.key

ekzorchik@srv-bionic:~$ sudo apt-key add nginx_signing.key

OK

ekzorchik@srv-bionic:~$

ekzorchik@srv-bionic:~$ sudo apt-get update

ekzorchik@srv-bionic:~$ apt-cache show nginx | grep Version | head -n5

Version: 1.25.0-1~bionic

Version: 1.23.4-1~bionic

Version: 1.23.3-1~bionic

Version: 1.23.2-1~bionic

Version: 1.23.1-1~bionic

ekzorchik@srv-bionic:~$

А тут вот такой нюанс, можно произвести обновление до версии аж 1.25:

ekzorchik@srv-bionic:~$ sudo apt-get install nginx

Reading package lists... Done

Building dependency tree

Reading state information... Done

The following packages were automatically installed and are no longer required:

  libgd3 libwebp6 libxslt1.1

Use 'sudo apt autoremove' to remove them.

The following additional packages will be installed:

  libpcre2-8-0

The following packages will be REMOVED:

  libnginx-mod-http-geoip libnginx-mod-http-image-filter

  libnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-stream nginx-common

  nginx-core

The following NEW packages will be installed:

  libpcre2-8-0

The following packages will be upgraded:

  nginx

1 upgraded, 1 newly installed, 7 to remove and 10 not upgraded.

Need to get 1,178 kB of archives.

After this operation, 1,908 kB of additional disk space will be used.

Do you want to continue? [Y/n] нажимаю клавишу "y"

ekzorchik@srv-bionic:~$ nginx -V

nginx version: nginx/1.25.0

built by gcc 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)

built with OpenSSL 1.1.1  11 Sep 2018

TLS SNI support enabled

configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-http_v3_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-g -O2 -fdebug-prefix-map=/data/builder/debuild/nginx-1.25.0/debian/debuild-base/nginx-1.25.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie'

ekzorchik@srv-bionic:~$

Далее, т.к. это Ubuntu система то Web-сервис работает от имени учетной записи www-data, а после обновления в конфигурационном файле /etc/nginx/nginx.conf для параметра user значится nginx изменяем его на www-data:

ekzorchik@srv-bionic:~$ cat /etc/passwd | grep www-data

www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin

ekzorchik@srv-bionic:~$ sudo nano /etc/nginx/nginx.conf

#Комментирую user nginx, а добавляю/изменяю на user www-data как принято в Ubuntu системах

#user nginx;

user  www-data;

worker_processes  auto;

error_log  /var/log/nginx/error.log notice;

pid        /var/run/nginx.pid;

events {

    worker_connections  1024;

}

http {

    include       /etc/nginx/mime.types;

    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

                      '$status $body_bytes_sent "$http_referer" '

                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;

    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    #Комментирую следующую строку, а прописываю ту которая используется в Ubuntu системах

    #include /etc/nginx/conf.d/*.conf;

    include /etc/nginx/sites-enabled/*;

}

ekzorchik@srv-bionic:~$ sudo chown -R www-data:www-data /var/www

ekzorchik@srv-bionic:~$ sudo rm -f /var/www/html/index.nginx-debian.html

ekzorchik@srv-bionic:~$ sudo rm -f /usr/share/nginx/html/index.html

ekzorchik@srv-bionic:~$ sudo nano /etc/nginx/nginx.conf

ekzorchik@srv-bionic:~$ sudo nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful

ekzorchik@srv-bionic:~$ sudo systemctl restart nginx

Итого, как оказалось достаточно легко выполнить обновление с дефолтной версии nginx на самую последнюю и, да еще с официальных репозитариев самого разработчика, остается дело за малым не порушить работу боевых сервисов, но и впредь использовать самую последнюю версию.

К примеру, на боевом сервисе для одного их наших разработчиков:

ekz@srv-tablo:~$ dpkg -l | grep nginx

ii  libnginx-mod-http-geoip                1.14.0-0ubuntu1.11                                                 amd64        GeoIP HTTP module for Nginx

ii  libnginx-mod-http-image-filter         1.14.0-0ubuntu1.11                                                 amd64        HTTP image filter module for Nginx

ii  libnginx-mod-http-xslt-filter          1.14.0-0ubuntu1.11                                                 amd64        XSLT Transformation module for Nginx

ii  libnginx-mod-mail                      1.14.0-0ubuntu1.11                                                 amd64        Mail module for Nginx

ii  libnginx-mod-stream                    1.14.0-0ubuntu1.11                                                 amd64        Stream module for Nginx

ii  nginx                                  1.14.0-0ubuntu1.11                                                 all          small, powerful, scalable web/proxy server

ii  nginx-common                           1.14.0-0ubuntu1.11                                                 all          small, powerful, scalable web/proxy server - common files

ii  nginx-core                             1.14.0-0ubuntu1.11                                                 amd64        nginx web/proxy server (standard version)

ekz@srv-tablo:~$

Произвожу обновление с учетом наработок выше:

ekz@srv-tablo:~$ sudo cp /etc/nginx/sites-enabled/default ~/nginx_enabled_default.conf

ekz@srv-tablo:~$

ekz@srv-tablo:~$ sudo apt-get install nginx

Reading package lists... Done

Building dependency tree

Reading state information... Done

The following packages were automatically installed and are no longer required:

  libpython-all-dev libpython-dev libpython2.7 libpython2.7-dev

  linux-headers-4.15.0-112 linux-headers-4.15.0-112-generic

  linux-image-4.15.0-112-generic linux-modules-4.15.0-112-generic

  linux-modules-extra-4.15.0-112-generic python-all python-all-dev

  python-asn1crypto python-cffi-backend python-crypto python-cryptography

  python-dbus python-dev python-enum34 python-gi python-idna python-ipaddress

  python-keyring python-keyrings.alt python-pkg-resources python-secretstorage

  python-setuptools python-six python-wheel python-xdg python2.7-dev shim

Use 'sudo apt autoremove' to remove them.

The following packages will be REMOVED:

  libnginx-mod-http-geoip libnginx-mod-http-image-filter

  libnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-stream nginx-common

  nginx-core

The following packages will be upgraded:

  nginx

1 upgraded, 0 newly installed, 7 to remove and 8 not upgraded.

Need to get 998 kB of archives.

After this operation, 1,359 kB of additional disk space will be used.

Do you want to continue? [Y/n] нажимаю клавишу "y"

ekz@srv-tablo:~$ sudo rm -f /var/www/html/index.nginx-debian.html

ekz@srv-tablo:~$ sudo rm /usr/share/nginx/html/index.html

ekz@srv-tablo:~$ sudo nano /etc/nginx/nginx.conf

user  www-data;

worker_processes  auto;

error_log  /var/log/nginx/error.log notice;

pid        /var/run/nginx.pid;

events {

    worker_connections  1024;

}

http {

    include       /etc/nginx/mime.types;

    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

                      '$status $body_bytes_sent "$http_referer" '

                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;

    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    #include /etc/nginx/conf.d/*.conf;

    include /etc/nginx/sites-enabled/*;

}

ekz@srv-tablo:~$ sudo nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful

ekz@srv-tablo:~$

ekz@srv-tablo:~$ sudo systemctl restart nginx

Проверив сервис, сервис работает. Пока оставляю как есть.

На заметку: Если что будет не работать на боевом, то и будем разбираться на этот счет, а после весь разбор найдет себя в виде заметке на блоге https://lin.ekzorchik.ru.

Итого заметка работоспособна, на этом все, с уважением автор блога Олло Александр aka ekzorchik.