Nginx升级从1.18.0 升级1.21.1(nginx升级到1.21.1)

张开发
2026/4/12 20:42:59 15 分钟阅读

分享文章

Nginx升级从1.18.0 升级1.21.1(nginx升级到1.21.1)
公司需求有个项目需要升级NGIXN1、首先查看ngxin版本[rootappcube-0008 nginx-1.21.0]# nginx -V nginx version: nginx/1.18.0 built by gcc 4.8.5 20150623 (EulerOS 4.8.5-28) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --prefix/usr/local/nginx --sbin-path/usr/local/nginx/sb in/nginx --conf-path/usr/local/nginx/conf/nginx.conf --error-log-path/var/lo g/nginx/error.log --http-log-path/var/log/nginx/access.log --pid-path/var/ru n/nginx/nginx.pid --lock-path/var/lock/nginx.lock --usernginx --groupnginx --with-compat --with-file-aio --with-threads --with-http_addition_module --wit h-http_auth_request_module --with-http_dav_module --with-http_flv_module --wit h-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --w ith-http_random_index_module --with-http_realip_module --with-http_secure_link _module --with-http_slice_module --with-http_ssl_module --with-http_stub_statu s_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-zlib/root/setup/zlib-1.2.11 --add-mod ule/root/setup/headers-more这里要注意的问题后续用到的这两个要注意可能因为环境的部署不一样所以路径不一样有的人喜欢放在opt目录下2、下载解压wget http://nginx.org/download/nginx-1.21.1.tar.gz tar -zxvf nginx-1.21.1.tar.gz cd nginx-1.21.13、编译这里就用到nginx -V看到的从 --prefix开始往后的参数[rootappcube-0008 nginx-1.21.1]# ls auto bash.sh CHANGES CHANGES.ru conf configure contrib html LICENSE Makefile man objs README src [rootappcube-0008 nginx-1.21.1]# cat bash.sh #我这里嫌麻烦改成了shell ./configure --prefix/usr/local/nginx --sbin-path/usr/local/nginx/sbin/nginx --conf-path/usr/local/nginx/conf/ng inx.conf --error-log-path/var/log/nginx/error.log --http-log-path/var/log/nginx/access.log --pid-path/var/run/n ginx/nginx.pid --lock-path/var/lock/nginx.lock --usernginx --groupnginx --with-compat --with-file-aio --with-th reads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module -- with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --wi th-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_s tub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream -- with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-zlib/root/setup/zlib-1 .2.11 --add-module/root/setup/headers-more4、make千万不要执行make installmake install 直接重装了环境就没了[rootlocalhost nginx-1.21.1]# make make -f objs/Makefile make[1]: Entering directory /setup/nginx-1.21.0 cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \ 。。。。 objs/src/http/modules/ngx_http_upstream_keepalive_module.o \ objs/src/http/modules/ngx_http_upstream_zone_module.o \ objs/src/http/modules/ngx_http_stub_status_module.o \ objs/ngx_modules.o \ -ldl -lpthread -lcrypt -lpcre -lssl -lcrypto -ldl -lpthread -lz \ -Wl,-E sed -e s|%%PREFIX%%|/opt/nginx| \ -e s|%%PID_PATH%%|/var/nginx/logs/nginx.pid| \ -e s|%%CONF_PATH%%|/var/nginx/conf/nginx.conf| \ -e s|%%ERROR_LOG_PATH%%|/var/nginx/logs/error.log| \ man/nginx.8 objs/nginx.8 make[1]: Leaving directory /root/setup/nginx-1.21.05、替换[rootappcube-0008 nginx-1.21.1]# ls auto bash.sh CHANGES CHANGES.ru conf configure contrib html LICENSE Makefile man objs README src [rootappcube-0008 nginx-1.21.1]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx-1.18.0 [rootappcube-0008 nginx-1.21.1]# cp objs/nginx /usr/local/nginx/sbin/6、依次启动新的主进程和新的工作进程.通过ps -ef | grep ngxin 查看kill -USR2 cat /var/run/nginx/nginx.pid #杀死主进程 kill -WINCH cat /var/run/nginx/nginx.pid.oldbin主进程长期不死的情况下直接kill -9 主进程7、最后结果8、升级完成

更多文章