Debian linux安装Nginx

安装准备条件:

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

导入官方 nginx 签名密钥,以验证软件包的真实性。获取密钥:

  • 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 ,应该返回如下所示:

  • pub   rsa2048 2011-08-19 [SC] [expires: 2024-06-14]

      573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62

uid   nginx signing key <signing-key@nginx.com>

如果返回指纹不同,请删除该文件。

选择你要安装的NGINX版本:

1.选择稳定的版本 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

2.如果您想使用主线版本 nginx ,请运行以下命令:

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,请运行以下命令:

  • sudo apt update

  • sudo apt install nginx