Nginx1.20.1平滑升级到Nginx1.24.0遇到的坑
本文最后更新于 572 天前,其中的信息可能已经有所发展或是发生改变。

Nginx1.20.1平滑升级到Nginx1.24.0遇到的坑

前提

Nginx1.20.1存在nginx 缓冲区错误漏洞(CVE-2022-41741)nginx 越界写入漏洞(CVE-2022-41742)漏洞,因此计划升级到Nginx1.24.0,但因为引入了sticky,升级过程中可能就编译出了几次错误。

升级过程

1.查看当前版本

./nginx -V
nginx version: nginx/1.20.1
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)
built with OpenSSL 1.1.1g  21 Apr 2020
TLS SNI support enabled
configure arguments: --prefix=/work_app/nginx2020 --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-pcre --with-http_ssl_module --with-openssl=/usr/local --add-module=/usr/local/src/nginx-sticky-module-1.2.6 --with-openssl-opt='enable-tls1_3 enable-weak-ssl-ciphers' --with-http_v2_module --with-http_sub_module

2.下载最新版

前往查看最新版,http://nginx.org/en/download.html

3.编译

./configure --prefix=/work_app/nginx2020 --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-pcre --with-http_ssl_module --with-openssl=/usr/local/openssl --add-module=/usr/local/src/nginx-sticky-module-1.2.6 --with-openssl-opt='enable-tls1_3 enable-weak-ssl-ciphers' --with-http_v2_module --with-http_sub_module #按原来的选项configure
make #编译

报错1

利用旧版本的编译参数来编译新版本nginx,make的时候,出现了错误

/bin/sh: line 2: ./config: No such file or directory
make[1]: *** [/usr/local/openssl/.openssl/include/openssl/ssl.h] Error 127
make[1]: Leaving directory `

从报错信息上看,可以看到编译是openssl相关的组件报错了,可能是“–with-openssl=/usr/local/openssl” 这个参数导致。这里提到了/usr/local/openssl/.openssl/include/openssl/ssl.h这个文件,我尝试去找这个文件,发现文件找不到:(/usr/local/openssl是我自己安装的openssl)

解决1

发现了问题可能的原因后,尝试修改一下nginx添加openssl模块时候的相关编译信息auto/lib/openssl/conf

# vi auto/lib/openssl/conf
            CORE_INCS="$CORE_INCS $OPENSSL/.openssl/include"
            CORE_DEPS="$CORE_DEPS $OPENSSL/.openssl/include/openssl/ssl.h"
            CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a"
            CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a"

# 在该文件中,看到openssl的core相关目录,都被添加上了.openssl这级目录,
# 尝试修改目录信息,去除.openssl这级目录:   
            CORE_INCS="$CORE_INCS $OPENSSL/include"
            CORE_DEPS="$CORE_DEPS $OPENSSL/include/openssl/ssl.h"
            CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libssl.a"
            CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libcrypto.a"

修改完auto/lib/openssl/conf的信息之后,重新编译安装nginx

make clean
./configure --prefix=/work_app/nginx2020 --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-pcre --with-http_ssl_module --with-openssl=/usr/local/openssl --add-module=/usr/local/src/nginx-sticky-module-1.2.6 --with-openssl-opt='enable-tls1_3 enable-weak-ssl-ciphers' --with-http_v2_module --with-http_sub_module
make

再次出现一个错误,报错信息如下:

报错2

/usr/local/src/nginx-sticky-module-1.2.6/ngx_http_sticky_module.c: 在函数‘ngx_http_init_sticky_peer’中:
/usr/local/src/nginx-sticky-module-1.2.6/ngx_http_sticky_module.c:207: 错误:‘ngx_http_headers_in_t’没有名为‘cookies’的成员
cc1: warnings being treated as errors
/usr/local/src/nginx-sticky-module-1.2.6/ngx_http_sticky_module.c:207: 错误:传递‘ngx_http_parse_multi_header_lines’的第 2 个参数时在不兼容的指针类型间转换
src/http/ngx_http.h:106: 附注:需要类型‘struct ngx_table_elt_t *’,但实参的类型为‘struct ngx_str_t *’
/usr/local/src/nginx-sticky-module-1.2.6/ngx_http_sticky_module.c:207: 错误:提供给函数‘ngx_http_parse_multi_header_lines’的实参太少
make[1]: *** [objs/addon/nginx-sticky-module-1.2.6/ngx_http_sticky_module.o] 错误 1
make[1]: Leaving directory `/usr/local/src/nginx-1.24.0'
make: *** [build] 错误 2

此次报错信息是nginx-sticky-module-1.2.6的问题,查找了一圈后,需要修改sticky下的ngx_http_sticky_module.c代码,找到以下代码进行注释,并且添加一行

    // if (ngx_http_parse_multi_header_lines(&r->headers_in.cookies, &iphp->sticky_conf->cookie_name, &route) != NGX_DECLINED) {
    if (ngx_http_parse_multi_header_lines(r, r->headers_in.cookie, &iphp->sticky_conf->cookie_name, &route) != NULL) {

修改ngx_http_sticky_misc.c代码,加入下面的头文件

#include <openssl/sha.h> 
#include <openssl/md5.h>

image-20221218221826360

重新编译安装nginx

make clean
./configure --prefix=/work_app/nginx2020 --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-pcre --with-http_ssl_module --with-openssl=/usr/local/openssl --add-module=/usr/local/src/nginx-sticky-module-1.2.6 --with-openssl-opt='enable-tls1_3 enable-weak-ssl-ciphers' --with-http_v2_module --with-http_sub_module
make

cd /usr/local/src/nginx-1.24.0
sbin/nginx -V #测试下,显示如下就是通过
#----输出
nginx version: nginx/1.24.0
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC) 
built with OpenSSL 1.1.1g  21 Apr 2020
TLS SNI support enabled
configure arguments: --prefix=/work_app/nginx2020 --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-pcre --with-http_ssl_module --with-openssl=/usr/local/openssl --add-module=/usr/local/src/nginx-sticky-module-1.2.6 --with-openssl-opt='enable-tls1_3 enable-weak-ssl-ciphers' --with-http_v2_module --with-http_sub_module

mv /work_app/nginx2020/sbin/nginx /work_app/nginx2020/sbin/nginx.old #移动旧版本
mv /usr/local/src/nginx-1.24.0/sbin/nginx /work_app/nginx2020/sbin/nginx #复制新版本nginx过去

4.启动新nginx,关掉旧nginx

# 让nginx把nginx.pid改成nginx.pid.oldbin 跟着启动新的nginx
kill -USR2 `cat /work_app/nginx2020/nginx.pid`
# 退出旧的nignx
kill -QUIT `cat /work_app/nginx2020/nginx.pid.oldbin`
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇