Debian 9 || 10 安装 Nginx

选择版本

nginx 分为 mainlinestable 两个版本,官方建议选择 mainline 版本,具体见:https://www.nginx.com/blog/nginx-1-6-1-7-released/

我这里引用官方的几段话来解释为什么官方建议使用 mainline 版本:

In NGINX nomenclature, “stable” means that no new features are added (the feature set is stable). Only major bug fixes are committed to that version.

NGINX 的命名中,“稳定” 意味着不会有新的功能加入(功能集稳定)。 只有主要错误修复会应用到这个版本。

Note that stable does not mean more reliable or more bug‑free. In fact, the mainline is generally regarded as more reliable because we port all bug fixes to it, and not just critical fixes as for the stable branch. On the other hand, changes in the stable branch are very unlikely to affect third‑party modules. We don’t make the same commitment concerning the mainline, where new features can affect the operation of third‑party modules.

请注意,稳定分支并不意味着更可靠或者更少的错误,事实上,通常情况下主线分支更可靠,因为我们将所有错误修复都应用到这上面,而并不像稳定分支仅仅只有关键错误修复,在其他方面,稳定分支的改变不太可能影响第三方模块。我们不会对主线做出相同的承诺,因为主线的新特性可能会影响第三方模块的运行。

We recommend that in general you deploy the NGINX mainline branch at all times. The main reason to use the stable branch is that you are concerned about possible impacts of new features, such as incompatibility with third‑party modules or the inadvertent introduction of bugs in new features.

通常情况下,我们推荐在任何时候部署 NGINXmainline 分支。使用稳定分支的主要原因是你担心新特性可能带来的影响,比如与第三方模块不兼容,或者无意中对新功能的错误引用。

NGINX Plus tracks the NGINX mainline branch, and adds some commercial‑only features

The internal version numbers in NGINX Plus match the mainline release with which NGINX Plus is most closely synchronized.

同样,在官方文章的底部,明确说明了:NGINX 的商业版本 NGINX Plus 也基于 mainline 版本,并且添加了一些仅限商业用户的功能,NGINX Plus 的内部版本号与 mainline 的最新版本相匹配。

开始安装

安装前置软件包

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

添加仓库

mainline 版本仓库

1
2
echo "deb http://nginx.org/packages/mainline/debian `lsb_release -cs` nginx" \
| sudo tee /etc/apt/sources.list.d/nginx.list

或者你也可以选择 stable 版本仓库

1
2
echo "deb http://nginx.org/packages/debian `lsb_release -cs` nginx" \
| sudo tee /etc/apt/sources.list.d/nginx.list

导入签名密钥

导入 nginx 官方的签名密钥,以便 apt 可以验证软件包的真实性:

1
curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add -

验证你现在的密钥是否正确:

1
sudo apt-key fingerprint ABF5BD827BD9BF62

确保上面的命令输出和下面的一样:

1
2
3
pub   rsa2048 2011-08-19 [SC] [expires: 2024-06-14]
573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62
uid [ unknown] nginx signing key <signing-key@nginx.com>

安装 nginx

1
2
sudo apt update
sudo apt install nginx

查看 nginx 版本号:

1
sudo nginx -v

启动 nginx

1
2
sudo systemctl start nginx
sudo systemctl enable nginx

成功 ~

欢迎关注我的其它发布渠道