nginx升级
1、源码包下载:http://nginx.org/en/download.html (nginx-1.20.2.tar.gz)
2、查看旧版本安装模块:nginx -V
nginx -V
nginx version: nginx/1.20.2 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --prefix=/etc/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 --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --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 --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_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-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
3、编译不安装
./configure --prefix=/etc/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 --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --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 --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_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-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
make
注:make后会生成一个objs文件夹
[root@ecs-20b8-0925717 nginx-1.20.2]# ls
auto CHANGES.ru configure html Makefile objs src
CHANGES conf contrib LICENSE man README
注:
nginx path prefix: "/etc/nginx"
nginx binary file: "/usr/sbin/nginx"
nginx modules path: "/usr/lib64/nginx/modules"
nginx configuration prefix: "/etc/nginx"
nginx configuration file: "/etc/nginx/nginx.conf"
nginx pid file: "/var/run/nginx.pid"
nginx error log file: "/var/log/nginx/error.log"
nginx http access log file: "/var/log/nginx/access.log"
nginx http client request body temporary files: "/var/cache/nginx/client_temp"
nginx http proxy temporary files: "/var/cache/nginx/proxy_temp"
nginx http fastcgi temporary files: "/var/cache/nginx/fastcgi_temp"
nginx http uwsgi temporary files: "/var/cache/nginx/uwsgi_temp"
nginx http scgi temporary files: "/var/cache/nginx/scgi_temp"
代表./configure执行成功,
objs/ngx_modules.o \
-Wl,-z,relro -Wl,-z,now -pie -ldl -lpthread -lpthread -lcrypt -lpcre -lssl -lcrypto -ldl -lpthread -lz \
-Wl,-E
sed -e "s|%%PREFIX%%|/etc/nginx|" \
-e "s|%%PID_PATH%%|/var/run/nginx.pid|" \
-e "s|%%CONF_PATH%%|/etc/nginx/nginx.conf|" \
-e "s|%%ERROR_LOG_PATH%%|/var/log/nginx/error.log|" \
< man/nginx.8 > objs/nginx.8
make[1]: Leaving directory `/usr/local/nginx-1.20.2'
代表make执行成功
4、查看安装需要的文件(找一台非正式环境的机器执行make install)
make install make -f objs/Makefile install make[1]: Entering directory `/usr/local/nginx-1.20.2' test -d '/etc/nginx' || mkdir -p '/etc/nginx' test -d '/usr/sbin' \ || mkdir -p '/usr/sbin' test ! -f '/usr/sbin/nginx' \ || mv '/usr/sbin/nginx' \ '/usr/sbin/nginx.old' cp objs/nginx '/usr/sbin/nginx' test -d '/etc/nginx' \ || mkdir -p '/etc/nginx' cp conf/koi-win '/etc/nginx' cp conf/koi-utf '/etc/nginx' cp conf/win-utf '/etc/nginx' test -f '/etc/nginx/mime.types' \ || cp conf/mime.types '/etc/nginx' cp conf/mime.types '/etc/nginx/mime.types.default' test -f '/etc/nginx/fastcgi_params' \ || cp conf/fastcgi_params '/etc/nginx' cp conf/fastcgi_params \ '/etc/nginx/fastcgi_params.default' test -f '/etc/nginx/fastcgi.conf' \ || cp conf/fastcgi.conf '/etc/nginx' cp conf/fastcgi.conf '/etc/nginx/fastcgi.conf.default' test -f '/etc/nginx/uwsgi_params' \ || cp conf/uwsgi_params '/etc/nginx' cp conf/uwsgi_params \ '/etc/nginx/uwsgi_params.default' test -f '/etc/nginx/scgi_params' \ || cp conf/scgi_params '/etc/nginx' cp conf/scgi_params \ '/etc/nginx/scgi_params.default' test -f '/etc/nginx/nginx.conf' \ || cp conf/nginx.conf '/etc/nginx/nginx.conf' cp conf/nginx.conf '/etc/nginx/nginx.conf.default' test -d '/var/run' \ || mkdir -p '/var/run' test -d '/var/log/nginx' \ || mkdir -p '/var/log/nginx' test -d '/etc/nginx/html' \ || cp -R html '/etc/nginx' test -d '/var/log/nginx' \ || mkdir -p '/var/log/nginx' make[1]: Leaving directory `/usr/local/nginx-1.20.2'
5、结合上面的输出内容对比正式环境中nginx的配置文件缺省的文件,将配置文件替换(注意保留自己的配置项)
我只替换了二进制文件
mv /usr/sbin/nginx /usr/sbin/nginx.old cp objs/nginx '/usr/sbin/nginx'
6、平滑升级
nginx -t(测试是否正常) # 查看nginx 主进程号 ps -ef|grep nginx # kill -USR2 PID(旧) # 发送WINCH信号给旧的主进程。然后,他的工作进程将从容关闭 kill -WINCH PID(旧) # 删除旧主进程 kill -QUIT 旧主进程号
7、如果多台相同环境的nginx需要升级,只需要将nginx二进制文件传到对应的/usr/sbin/下,执行平滑升级过程就可以了
参考:
平滑升级原理:https://www.cnblogs.com/wupeixuan/p/12074007.html
平滑升级操作:https://www.cnblogs.com/try-better-tomorrow/p/5099662.html
本文来自博客园,作者:zk01,转载请注明原文链接:https://www.cnblogs.com/zhangxiaokui/p/16068384.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异