环境说明
当前是 CentOS7 服务器。
点击进入 nginx 下载页面
环境准备
nginx -V
可以看出当前版本为 1.16.1,如下图所示:
下载当前最新版本 nginx-1.24.0
,并通过上传至服务器,然后执行解压命令。
tar -zxvf nginx-1.24.0.tar.gz
解压后,对最新版 nginx 进行配置
查看现有版本(老版本)nginx 的 configure
配置信息
nginx -V
如图所示,得到 configure
的配置信息。
然后,再对新版 nginx 进行配置
./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-stream_ssl_preread_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-http_auth_request_module --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E'
接着,进行 make
make
进行编译,切记千万不要输入 make install
对老版本 sbin 目录下的 nginx 进行备份:
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
将编译好的 objs
目录下的 nginx
文件,复制到 /usr/local/nginx/sbin
目录。
cp /opt/nginx-1.24.0/objs/nginx /usr/local/nginx/sbin/nginx
make upgrade 命令升级
对 nginx 升级
在新版本目录下执行命令
make upgrade
查看升级后的版本
错误解决
编译时错误
1、编译错误1
./configure: error: the invalid value in
--with-ld-opt="-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E"
解决:
yum install redhat-rpm-config
2、编译错误2
./configure: error: the HTTP XSLT module requires the libxml2/libxslt libraries.
You can either do not enable the module or install the libraries.
解决:
yum install libxslt-devel
3、编译错误3
./configure: error: the HTTP image filter module requires the GD library.
You can either do not enable the module or install the libraries.
解决:
yum install gd-devel
4、编译错误4
./configure: error: perl module ExtUtils::Embed is required
解决:
yum install perl-ExtUtils-Embed
./configure: error: the GeoIP module requires the GeoIP library.
You can either do not enable the module or install the library.
5、编译错误5
./configure: error: the GeoIP module requires the GeoIP library.
You can either do not enable the module or install the library.
解决:
yum install geoip-devel
6、编译错误6
./configure: error: the Google perftools module requires the Google perftools
library. You can either do not enable the module or install the library.
解决:
yum install gperftools-devel
7、编译错误7
./configure: warning: the "--with-ipv6" option is deprecated
解决:不需要处理
升级时错误
root@PROD-SVR-DEV-02 /opt/nginx-1.24.0$ make upgrade
/usr/sbin/nginx -t
nginx: [emerg] module "/usr/lib64/nginx/modules/ngx_http_image_filter_module.so" version 1016001 instead of 1024000 in /usr/share/nginx/modules/mop-image-filter.conf:1
nginx: configuration file /etc/nginx/nginx.conf test failed
make: *** [upgrade] Error 1
说明有旧版本的 Nginx 模块,进到目录 /usr/share/nginx/modules
,重命名这些不需要 .conf
扩展文件,后面都加个.old
。
然后再测试一遍