• Linux利用源码包升级Nginx到1.23.1用以解决nginx安全漏洞问题


    目录

    背景

    准备工作

    升级

    验证


    背景

    升级nginx到1.23.1用以解决以下下安全漏洞问题

    NGINX 环境问题漏洞(CVE-2019-20372)
    NGINX 环境问题漏洞(CVE-2020-12440)
    NGINX 拒绝服务漏洞(CVE-2016-4450)
    NGINX RANGE FILTER模块数字错误漏洞(CVE-2017-7529)

    准备工作

    1、配置本地yum源安装基础编译环境

    yum -y install openssl openssl-devel make zlib zlib-devel gcc gcc-c++ libtool    pcre pcre-devel pam pam-devel

    2、原Nginx信息获取

    1. [root@centos111 sbin]# ./nginx -V
    2. nginx version: nginx/1.18.0
    3. built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
    4. built with OpenSSL 1.0.2k-fips 26 Jan 2017
    5. TLS SNI support enabled
    6. configure arguments: --prefix=/usr/local/nginx --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-pcre --with-http_ssl_module
    7. [root@centos111 sbin]#

    3、升级包下载(本例已最新版1.23.1为例)

    Index of /download/ (nginx.org)

    升级

    1、上传新版本源码包到服务器并解压(本例/opt/soft/nginx)

    1. -rw-r--r-- 1 root root 1104352 721 10:16 nginx-1.23.1.tar.gz
    2. [root@centos111 nginx]# pwd
    3. /opt/soft/nginx
    4. [root@centos111 nginx]# ll
    5. 总用量 1080
    6. -rw-r--r-- 1 root root 1104352 721 10:16 nginx-1.23.1.tar.gz
    7. [root@centos111 nginx]# tar -xvzf nginx-1.23.1.tar.gz
    8. [root@centos111 nginx]# ll
    9. 总用量 1080
    10. drwxr-xr-x 8 elasticsearch elasticsearch 158 719 22:05 nginx-1.23.1
    11. -rw-r--r-- 1 root root 1104352 721 10:16 nginx-1.23.1.tar.gz
    12. [root@centos111 nginx]#

    2、进入解压目录并按照旧版本的配置进行编译前的配置(旧版本配置信息请查看【准备工作】中的第二步),正确执行完成后输出类似如下结果(执行过程略)

    1. [root@centos111 nginx]# cd nginx-1.23.1/
    2. [root@centos111 nginx-1.23.1]# ./configure --prefix=/usr/local/nginx --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-pcre --with-http_ssl_module
    3. 过程略
    4. checking for PCRE library ... found
    5. checking for PCRE JIT support ... found
    6. checking for OpenSSL library ... found
    7. checking for zlib library ... found
    8. creating objs/Makefile
    9. Configuration summary
    10. + using system PCRE library
    11. + using system OpenSSL library
    12. + using system zlib library
    13. nginx path prefix: "/usr/local/nginx"
    14. nginx binary file: "/usr/local/nginx/sbin/nginx"
    15. nginx modules path: "/usr/local/nginx/modules"
    16. nginx configuration prefix: "/usr/local/nginx/conf"
    17. nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
    18. nginx pid file: "/usr/local/nginx/logs/nginx.pid"
    19. nginx error log file: "/usr/local/nginx/logs/error.log"
    20. nginx http access log file: "/usr/local/nginx/logs/access.log"
    21. nginx http client request body temporary files: "client_body_temp"
    22. nginx http proxy temporary files: "proxy_temp"
    23. nginx http fastcgi temporary files: "fastcgi_temp"
    24. nginx http uwsgi temporary files: "uwsgi_temp"
    25. nginx http scgi temporary files: "scgi_temp"
    26. 您在 /var/spool/mail/root 中有新邮件
    27. [root@centos111 nginx-1.23.1]#

    3、编译生成objs目录,执行make进行编译,编译正常结果如下,执行ll查看发现多了一个objs目录

    1. [root@centos111 nginx-1.23.1]# make
    2. 过程略
    3. objs/src/http/modules/ngx_http_upstream_zone_module.o \
    4. objs/src/http/modules/ngx_http_stub_status_module.o \
    5. objs/ngx_modules.o \
    6. -ldl -lpthread -lcrypt -lpcre -lssl -lcrypto -ldl -lpthread -lz \
    7. -Wl,-E
    8. sed -e "s|%%PREFIX%%|/usr/local/nginx|" \
    9. -e "s|%%PID_PATH%%|/usr/local/nginx/logs/nginx.pid|" \
    10. -e "s|%%CONF_PATH%%|/usr/local/nginx/conf/nginx.conf|" \
    11. -e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" \
    12. < man/nginx.8 > objs/nginx.8
    13. make[1]: 离开目录“/opt/soft/nginx/nginx-1.23.1”
    14. 您在 /var/spool/mail/root 中有新邮件
    15. [root@centos111 nginx-1.23.1]# ll
    16. 总用量 808
    17. drwxr-xr-x 6 elasticsearch elasticsearch 326 7月 21 10:24 auto
    18. -rw-r--r-- 1 elasticsearch elasticsearch 319222 7月 19 22:05 CHANGES
    19. -rw-r--r-- 1 elasticsearch elasticsearch 487813 7月 19 22:05 CHANGES.ru
    20. drwxr-xr-x 2 elasticsearch elasticsearch 168 7月 21 10:24 conf
    21. -rwxr-xr-x 1 elasticsearch elasticsearch 2590 7月 19 22:05 configure
    22. drwxr-xr-x 4 elasticsearch elasticsearch 72 7月 21 10:24 contrib
    23. drwxr-xr-x 2 elasticsearch elasticsearch 40 7月 21 10:24 html
    24. -rw-r--r-- 1 elasticsearch elasticsearch 1397 7月 19 22:05 LICENSE
    25. -rw-r--r-- 1 root root 438 7月 21 10:27 Makefile
    26. drwxr-xr-x 2 elasticsearch elasticsearch 21 7月 21 10:24 man
    27. drwxr-xr-x 3 root root 174 7月 21 10:30 objs
    28. -rw-r--r-- 1 elasticsearch elasticsearch 49 7月 19 22:05 README
    29. drwxr-xr-x 9 elasticsearch elasticsearch 91 7月 21 10:24 src

    4、备份旧版程序并覆盖新版本

    1. [root@centos111 nginx-1.23.1]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx_1.18
    2. [root@centos111 nginx-1.23.1]# cp ./objs/nginx /usr/local/nginx/sbin/nginx

    5、平滑升级

    1. [root@centos111 nginx-1.23.1]# make upgrade
    2. /usr/local/nginx/sbin/nginx -t
    3. nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
    4. nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
    5. kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
    6. sleep 1
    7. test -f /usr/local/nginx/logs/nginx.pid.oldbin
    8. kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`
    9. [root@centos111 nginx-1.23.1]#

    验证

    1. [root@centos111 nginx-1.23.1]# /usr/local/nginx/sbin/nginx -v
    2. nginx version: nginx/1.23.1
    3. [root@centos111 nginx-1.23.1]#

  • 相关阅读:
    模拟 Junit 框架
    24张宇八套卷复盘(五)
    MYSQL基础——函数
    u盘资料不小心删掉怎么找回来?一文教会你恢复方法
    windows server 2012安装教程
    javaweb_05:请求响应——请求
    3.Vue-在Vue框架中搭建路由
    设计模式---代理模式
    PCB叠层设计
    Windows Server 2008(6.1)安装KB2533623系统补丁
  • 原文地址:https://blog.csdn.net/u010976445/article/details/125893515