笔记---Nginx平滑升级以及遇到问题记录

本文详细记录了在Ubuntu 18.08系统上,从Nginx 1.14.0平滑升级到1.21.4的过程中遇到的各种依赖错误,包括PCRE、zlib、libxml2/libxslt、GD库、GeoIP库以及ngx_http_passenger_module.so版本不匹配等问题,提供了相应的解决方法和参考资料。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1 背景

系统为Ubuntu18.08,Nginx的旧版本为1.14.0,升级新版本为1.21.4;服务器上正在运行着服务,因此采用平滑升级的方式进行nginx升级。非root用户

2 平滑升级

(1)在不停掉老进程的情况下,启动新进程。

(2)老进程负责处理仍然没有处理完的请求,但不再接受处理请求。

(3)新进程接受新请求。

(4)老进程处理完所有请求,关闭所有连接后,停止。

这样就很方便地实现了平滑升级。一般有两种情况下需要升级Nginx,一种是确实要升级Nginx的版本,另一种是要为Nginx添加新的模块。

3 平滑升级命令

cd /mnt

# 下载nginx升级包
sudo wget http://nginx.org/download/nginx-1.21.4.tar.gz

# 解压升级包
sudo tar zxvf nginx-1.21.4.tar.gz

cd nginx-1.21.4/

# 查看当前版本得到编译参数
sudo /usr/sbin/nginx -V
# 参数:configure arguments: --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-H4cN7P/**nginx-1.14.0**=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_geoip_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-mail=dynamic --with-mail_ssl_module

# 用上面编译参数,参数中的版本需要修改
sudo ./configure --prefix=/usr/local/nginx --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-H4cN7P/nginx-1.21.4=. -fstack-protector-strong....... 
# 执行这一步时可能会出现很多module找不到,可以尝试自己添加;找不到的话可以先将add-module及后面的路径地址删除,先执行下去。

# 编译make,千万别make install
sudo make

# make编译完后,在objs目录下就多了个nginx,这个就是新版本的程序了

# 备份原nginx文件
sudo mv /usr/sbin/nginx /usr/sbin/nginx-20211111

# 将新生成nginx执行文件复制到nginx/sbin下
sudo cp objs/nginx /usr/sbin/nginx

# 检测配置文件是否正确
sudo /usr/sbin/nginx -t

# 执行升级(通过拷贝替换的方式可以不执行这一步了)
make upgrade

# 执行完后
sudo /usr/sbin/nginx -V

# 到此就完成平滑升级。

参考文档:https://cloud.tencent.com/developer/article/1139955

4 升级过程中遇到的问题及解决方案

4.1 错误1:error: the HTTP rewrite module requires the PCRE library

错误信息:

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

解决:

# 需要安装pcre包。
sudo apt-get update
sudo apt-get install libpcre3 libpcre3-dev
# 你可能还需要安装
sudo apt-get install openssl libssl-dev

参考链接:
https://blog.csdn.net/pengshengli/article/details/86694967

4.2 错误2:error: the HTTP gzip module requires the zlib library.

错误信息:

./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.

解决:

# 找一个版本下载,解压、安装(安装前先configure)
http://zlib.net/
# 使用的是1.2.11

参考链接:
https://blog.csdn.net/pengshengli/article/details/86694967
https://www.jb51.net/article/80468.htm

4.3 错误3:error: the HTTP XSLT module requires the libxml2/libxslt libraries.

错误信息:

./configure: error: the HTTP XSLT module requires the libxml2/libxslt libraries. 
You can either do not enable the module or install the libraries.

解决:

# 需要安装libxslt包。
sudo apt-get update
sudo apt-get install libxslt-dev
# 你可能还需要安装
sudo apt-get install libgd-dev # for the "error: the HTTP image filter module requires the GD library." error
sudo apt-get install libgeoip-dev # for the GeoIP package

参考链接:
https://stackoverflow.com/questions/57415360/configure-error-the-http-xslt-module-requires-the-libxml2-libxslt-libraries
https://cloud.tencent.com/developer/article/1401078

4.4 错误4:error: the HTTP image filter module requires the GD library.

错误信息:


                
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值