本人仅适用使用 RPM 安装的Nginx
目录
在线升级
新增repo配置文件
在 YUM 仓库的目录(/etc/yum.repos.d/)下新增文件 nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
更新YUM缓存
[dev@web03 nginx]$ sudo yum clean all
[dev@web03 nginx]$ sudo yum makecache
升级Nginx
[dev@web03 nginx]$ yum update nginx
升级完成后可使用nginx -V检查确认配置
离线升级
下载rpm应用
在 Index of /packages/centos/ 下载最新版本的Nginx文件
wget http://nginx.org/packages/rhel/7/x86_64/RPMS/nginx-1.22.1-1.el7.ngx.x86_64.rpm
由于Nginx 依赖 pcre2 库,请下载对应系统版本的pcre2库文件,否则直接更新会报错
[dev@web03 nginx]$ rpm -Uvh nginx-1.22.1-1.el7.ngx.x86_64.rpm
warning: nginx-1.22.1-1.el7.ngx.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 7bd9bf62: NOKEY
error: Failed dependencies:
libpcre2-8.so.0()(64bit) is needed by nginx-1:1.22.1-1.el7.ngx.x86_64
下载pcre2文件
可在 rpmfind 站点搜索
wget http://www.rpmfind.net/linux/centos/7.9.2009/os/x86_64/Packages/pcre2-10.23-2.el7.x86_64.rpm
安装升级
安装pcre2
sudo rpm -ivh pcre2-10.23-2.el7.x86_64.rpm
更新nginx
sudo rpm -Uvh nginx-1.22.1-1.el7.ngx.x86_64.rpm
重启检查
查看新升级版本
[dev@web03 nginx]$ nginx -V
nginx version: nginx/1.22.1
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'
重新加载
[dev@web03 nginx]$ sudo nginx -s reload
参考资料