Debian 升级 Nginx 到最新版
一直在在使用腾讯云的轻量服务器跑的博客,nginx
版本有大半年未更新了,为了体验下nginx
最新的某些特性,便想着更新一下nginx
到最新的版本。
这里记录一下更新失败的错误和解决办法:
nginx -v
查看当前nginx
版本。
最开始使用命令apt-get update
想着更新最新版本:
root@VM-8-15-debian:~# apt-get update
Hit:1 http://mirrors.tencentyun.com/debian buster InRelease
Hit:2 http://mirrors.tencentyun.com/debian buster-updates InRelease
Hit:3 http://mirrors.tencentyun.com/debian-security buster/updates InRelease
Hit:4 https://mirrors.ustc.edu.cn/docker-ce/linux/debian buster InRelease
Hit:5 http://repo.mysql.com/apt/debian buster InRelease
Hit:6 https://download.docker.com/linux/debian buster InRelease
Reading package lists... Done
提示无任何更新内容。想想不应该啊,应该是nginx
的最新版本的下载源没有添加到。于是查看apt
源。
vi /etc/apt/sources.list
eb http://mirrors.tencentyun.com/debian buster main contrib non-free
# deb-src http://mirrors.tencentyun.com/debian buster main contrib non-free
deb http://mirrors.tencentyun.com/debian buster-updates main contrib non-free
# deb-src http://mirrors.tencentyun.com/debian buster-updates main contrib non-free
deb http://mirrors.tencentyun.com/debian-security buster/updates main contrib non-free
# deb-src http://mirrors.tencentyun.com/debian-security buster/updates main contrib non-free
# deb http://mirrors.tencentyun.com/debian buster-backports main contrib non-free
# deb-src http://mirrors.tencentyun.com/debian buster-backports main contrib non-free
# deb http://mirrors.tencentyun.com/debian buster-proposed-updates main contrib non-free
# deb-src http://mirrors.tencentyun.com/debian buster-proposed-updates main contrib non-free
deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/debian buster stable
# deb-src [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/debian buster stable
这里记录一下在
xshell
中无法右键复制vim
内的内容解决方法:
在当前执行vi
命令的路径新建文件vi .vimrc
编辑以下内容:set mouse=c
退出保存即可
百度搜索nginx debian
的下载源,某博文显示其源为:
deb http://nginx.org/packages/mainline/ubuntu/ codename nginx
deb-src http://nginx.org/packages/mainline/ubuntu/ codename nginx
说明:
codename
为系统代码,查看本机系统代号使用命令:
lsb_release -cs
将输出结果替换
codename
将下载源添加至/etc/apt/sources.list
文件内,再执行apt-get update
,提示请求某个IP 404错误。不解!
无奈,只好寻求官网,果然官网才是YYDS
,参考:http://nginx.org/en/linux_packages.html#Debian
首先,卸载原有的nginx
版本:
sudo apt remove nginx nginx-common nginx-full nginx-core
- 安装必备组件:
sudo apt install curl gnupg2 ca-certificates lsb-release debian-archive-keyring
- 导入一个官方的nginx签名密钥,以便apt可以验证软件包的真实性。获取密钥:
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
| sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
- 验证下载的文件是否包含正确的密钥:
gpg --dry-run --quiet --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg
输出应该包含完整的指纹573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62,如下所示:
root@VM-8-15-debian:~# gpg --dry-run --quiet --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg
pub rsa2048 2011-08-19 [SC] [expires: 2024-06-14]
573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62
uid nginx signing key
- 如果指纹不同,请删除该文件。
要为稳定的nginx
软件包设置apt
仓库,请运行以下命令:
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/debian `lsb_release -cs` nginx" \
| sudo tee /etc/apt/sources.list.d/nginx.list
- 设置存储库锁定以优先使用官方软件包,而不是发行版提供的软件包:
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \
| sudo tee /etc/apt/preferences.d/99nginx
- 执行安装更新步骤:
sudo apt update
sudo apt install nginx
PS: 更新前请先备份您的
Nginx
配置文件,例如:cp /etc/nginx/conf.d/myweb.conf /root/myweb.conf
Ends.
Debian 升级 Nginx 到最新版
本博客所有文章除特别声明外,均采用
CC BY-NC-SA 4.0
许可协议。转载请注明来自 Hi I'm LouisLan!
评论
0 评论