Skip to content

Yum 更新 Nginx 版本

不管是腾讯云还是阿里云,默认的 nginx 版本可能不够新,那么如何更新呢?

1. 首先我们要 配置 nginx 的 repo

安装 yum-utils

yum install yum-utils

编辑 /etc/yum.repos.d/nginx.repo 写入一下内容

ini
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

2. 更新操作

yum repolist 命令获得列表, 默认获取了上面的 stable

bash
repo id                                                         repo name
appstream                                                       Rocky Linux 9 - AppStream
baseos                                                          Rocky Linux 9 - BaseOS
copr:copr.fedorainfracloud.org:ngompa:musl-libc                 Copr repo for musl-libc owned by ngompa
copr:copr.fedorainfracloud.org:zhullyb:v2rayA                   Copr repo for v2rayA owned by zhullyb
docker-ce-stable                                                Docker CE Stable - x86_64
extras                                                          Rocky Linux 9 - Extras
nginx-stable                                                    nginx stable repo

上面只看到了 stable 稳定版本, 启用 mainline 主线

yum-config-manager --enable nginx-mainline

yum repolist 命令获得列表, 可以看到 mainline 也有了

bash
repo id                                                         repo name
appstream                                                       Rocky Linux 9 - AppStream
baseos                                                          Rocky Linux 9 - BaseOS
copr:copr.fedorainfracloud.org:ngompa:musl-libc                 Copr repo for musl-libc owned by ngompa
copr:copr.fedorainfracloud.org:zhullyb:v2rayA                   Copr repo for v2rayA owned by zhullyb
docker-ce-stable                                                Docker CE Stable - x86_64
extras                                                          Rocky Linux 9 - Extras
nginx-mainline                                                  nginx mainline repo
nginx-stable                                                    nginx stable repo

更新 nginx

yum update nginx

yum update --enablerepo=nginx-stable nginx

参考地址