环境准备
操作系统:centos7.9
环境:提前安装的nginx1.22.0,后续升级的nginx1.23.0的软件包
操作平台:VMware 17
操作步骤
查看升级前nginx版本
[root@bogon ~]# /usr/local/nginx/sbin/nginx -V
备份原文件
[root@bogon ~]# cp -pdr /usr/local/nginx/ /usr/local/nginx.bak
[root@bogon ~]# ls /usr/local/
下载需要升级到的nginx版本的软件包
也可以在官网下载后上传到centos中
[root@bogon ~]# wget http://nginx.org/download/nginx-1.23.0.tar.gz
解压nginx新版本软件压缩包
[root@bogon ~]# tar xvf nginx-1.23.0.tar.gz
[root@bogon ~]# ls
编译
切换到解压后的nginx文件夹内执行,只需要make,不需要make install,如果执行make install会将原来的配置文件覆盖掉
[root@bogon ~]# cd nginx-1.23.0
[root@bogon nginx-1.23.0]# ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--with-http_gunzip_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_realip_module \
--http-client-body-temp-path=/usr/local/nginx/client \
--http-proxy-temp-path=/usr/local/nginx/proxy \
--http-fastcgi-temp-path=/usr/local/nginx/fastcgi \
--http-uwsgi-temp-path=/usr/local/nginx/uwsgi \
--http-scgi-temp-path=/usr/local/nginx/scgi \
[root@bogon nginx-1.23.0]# make
参数
prefix:配置安装目录
user:nginx运行时的非特权用户
group:nginx运行时的非特权用户组
pid-path:nginx运行时pid的目录
lock-path:锁定文件目录,防止误操作,或其他使用
error-log-path:nginx错误日志目录
http-log-path:nginx运行日志目录
with-http_gzip_static_module:开启gz模块,压缩静态页面
with-http_gunzip_module:
with-http_ssl_module:开启ssl模块
with-http_stub_status_module:nginx的客户端状态
with-http_realip_module:
http-client-body-temp-path=/usr/local/nginx/client:设定客户端请求的临时目录
http-proxy-temp-path=/usr/local/nginx/proxy:设定http代理临时目录
http-fastcgi-temp-path=/usr/local/nginx/fastcgi:设定fastcgi临时目录
http-uwsgi-temp-path=/usr/local/nginx/uwsgi:设定uwsgi临时目录
http-scgi-temp-path=/usr/local/nginx/scgi:设定scgi临时目录
停止nginx
[root@bogon ~]# systemctl stop nginx
[root@bogon ~]# systemctl status nginx
复制nginx-1.23.0下的nginx到原来的nginx目录下
注意nginx-1.23.0中nginx在objs目录下而不是在sbin下面
[root@bogon ~]# cp /root/nginx-1.23.0/objs/nginx /usr/local/nginx/sbin/
cp: overwrite ‘/usr/local/nginx/sbin/nginx’? y
测试是否替换成功
[root@bogon ~]# systemctl start nginx
[root@bogon ~]# /usr/local/nginx/sbin/nginx -V
注意:
我这里的启停都是基于我已经把nginx注册成为一个服务了
如果未注册为服务,需要用另一种启停方式
cd /usr/local/nginx/sbin/
启动nginx: ./nginx
停止nginx: ./nginx -s stop
重新加载nginx: ./nginx -s reload