Nginx篇:通过apt的nginx官方仓库安装

介绍

为什么需要通过官方仓库安装? 答:系统默认的软件源版本太低

Debian

参考教程 https://nginx.org/en/linux_packages.html#Debian

前提条件:

1
sudo apt install curl gnupg2 ca-certificates lsb-release debian-archive-keyring

导入密钥,验证包的正确性:

1
2
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
    | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null

验证下载的文件是否包含正确的密钥:

1
gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg

输出应包含完整指纹573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62如下:

pub rsa2048 2011-08-19 [SC] [expires: 2024-06-14] 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 uid nginx signing key signing-key@nginx.com

如果指纹不同,删除文件。

二选一:

  • 要为稳定的 nginx 包设置 apt 存储库,请运行以下命令:
1
2
3
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/mainline/debian `lsb_release -cs` nginx" \
    | sudo tee /etc/apt/sources.list.d/nginx.list
  • 如果希望使用 mainline nginx 包,请改为运行以下命令:
1
2
3
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/mainline/debian `lsb_release -cs` nginx" \
    | sudo tee /etc/apt/sources.list.d/nginx.list

设置存储库固定,使用Nginx官方的软件包而不是发行版提供的软件包:

1
2
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \
    | sudo tee /etc/apt/preferences.d/99nginx

要安装 nginx,请运行以下命令:

1
2
sudo apt update
sudo apt install nginx

Ubuntu

参考教程 https://nginx.org/en/linux_packages.html#Ubuntu

前提条件:

1
sudo apt install curl gnupg2 ca-certificates lsb-release ubuntu-keyring

导入密钥,验证包的正确性:

1
2
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
    | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null

验证下载的文件是否包含正确的密钥:

1
gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg

输出应包含完整指纹573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62如下:

pub rsa2048 2011-08-19 [SC] [expires: 2024-06-14] 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 uid

如果指纹不同,删除文件。

二选一:

  • 要为稳定的 nginx 包设置 apt 存储库,请运行以下命令:
1
2
3
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \
    | sudo tee /etc/apt/sources.list.d/nginx.list
  • 如果希望使用 mainline nginx 包,请改为运行以下命令:
1
2
3
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/mainline/ubuntu `lsb_release -cs` nginx" \
    | sudo tee /etc/apt/sources.list.d/nginx.list

设置存储库固定,使其更喜欢我们的软件包而不是发行版提供的软件包:

1
2
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \
    | sudo tee /etc/apt/preferences.d/99nginx

要安装 nginx,请运行以下命令:

1
2
sudo apt update
sudo apt install nginx
使用 Hugo 构建
主题 StackJimmy 设计