Nginx版本升级

1.官网下载

地址:nginx: download

下载Stable version版本第二列(nginx-1.24.0)

2.准备工作
# 解压tar包到当前目录
tar -zxvf nginx-1.24.0.tar.gz
# 查看Nginx启动使用模块信息(大写 V)
# configure arguments:后面的内容第3步使用
nginx -V
# 准备编译安装需要使用的一些插件(已经有的可以忽略这一步)
## RHEL/CentOS yum方式
sudo yum install gcc make pcre-devel openssl-devel zlib-devel GeoIP-devel ImageMagick-devel libxml2-devel libxslt-devel gd-devel
## Debian或Ubuntu apt-get方式
sudo apt-get install build-essential libpcre3-dev libssl-dev zlib1g-dev libgeoip-dev libmagickwand-dev libxml2-dev libxslt1-dev libgd-dev
# 进入解压后目录赋权(configure 为绿色则有权限)
cd /usr/local/nginx-1.24.0/
chmod +x configure
3.制作二进制文件
# 注意该步骤需要复制自己的配置参数信息,需要与之前配置参数一致,下面只是我个人的,仅供参考
# --prefix 为自己的nginx二进制文件;--conf-path 为nginx配置文件
./configure --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-YlUNvj/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
# 完成后使用 make即可,不要使用make install,会将原来的配置文件覆盖
make
# make 后解压目录下的./objs/nginx 即为新的二进制文件
4.替换升级
# 备份旧的nginx二进制文件
# 注意!!!地址不一定为 --prefix指向的目录
whereis nginx
# 其中大概率为 目录包含 /sbin/ 的为实际二进制文件所在
cd /usr/sbin/
# 备份旧的文件,加上时间后缀
mv /usr/sbin/nginx /usr/sbin/nginx_$(date +%F)
# 复制新的nginx二进制文件
cp /usr/local/nginx-1.24.0/objs/nginx /usr/sbin/
# 测试新版本的nginx是否正常
./nginx -t
# 停止原nginx
./nginx_2024-04-10 -s stop
# 启动新nginx
./nginx
# 验证版本为新版本
./nginx -V

  • 8
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值