目录

Nginx升级

nginx升级

1. 查询原版本nginx自编译参数

1
2
ps -ef | grep nginx ## 查看nginx路径
nginx -V ## 根据查询到的路径查看自编译参数

2. 下载最新nginx包并编译

1
2
3
4
5
cd /opt
tar xf nginx-1.22.0.tar.gz
cd nginx-1.22.0
./configure --prefix=/opt/nginx --with-http_ssl_module ..... ## 根据第一步查询到的自编译参数填入
make

3. 替换启动文件

1
2
3
4
5
6
mv /usr/sbin/nginx /usr/sbin/nginx-日期 ## 备份原启动文件
cp /opt/nginx-1.22.0/objs/nginx /usr/sbin/nginx
nginx -t ## 检查配置无误
nginx -s reload
ps -ef| grep nginx ## 查看进程是否存在
nginx -v ## 查看nginx版本是否为新版本

4. 重启nginx

1
2
nginx -s stop
nginx

问题处理

1. ./configure未报错,编译报错,提示ngx_http_proxy_connect_module模块里的变量错误

添加了ngx_http_proxy_connect_module模块的部分nginx,由于之前用的模块是旧版本,需更新此模块方可编译成功。

1
2
3
4
5
# 将ngx_http_proxy_connect_module包解压在/opt下
cd /opt/nginx-1.22.0
patch -p1 < /opt/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_102101.patch
./configure时修改--add-module=/opt/ngx_http_proxy_connect_module
make

2. 编译报错,提示/opt/pcre-8.45/…….relocation R_X86_64_32S against `.rodata‘ can not be used when making a PIE object; recompile with -fPIC

  1. 网上解决方案:
  • 重新编译:make clean && make

没用,再次报错

  • 编辑/opt/nginx-1.22.0/objs/Makefile
1
2
3
# vim /opt/nginx-1.22.0/objs/Makefile
# 在 CFLAGS变量后加上-fPIC
CFLAGS = ......... -fPIC

然后重新编译。没用

  1. 无法定位问题,将重点转移至pcre,因为是在pcre处报的错,遂将./configure中的–with-pcre=….删除,使用系统自带的pcre

解决