Nginx是一个著名的Web服务器,具有开源访问权限,由于其广泛的支持而被顶级公司使用。该软件以其对内存资源的影响小、可扩展性高以及模块化的事件驱动架构而闻名,可提供安全、可预测的性能。Nginx不仅仅是一个Web服务器,还可以用作负载均衡器,HTTP缓存和反向代理。由于它是免费的开源软件(FOSS)和高性能HTTP网络服务器,因此您可以自由使用,修改和分发它,而无需花钱。
在 Debian 11 靶心上安装 nginx 主线版本
第 1 步。在我们安装任何软件之前,通过在终端中运行以下命令来确保您的系统是最新的非常重要:apt
<span class="pln">sudo apt update sudo apt upgrade sudo apt install curl gnupg2 ca</span><span class="pun">-</span><span class="pln">certificates lsb</span><span class="pun">-</span><span class="pln">release dirmngr software</span><span class="pun">-</span><span class="pln">properties</span><span class="pun">-</span><span class="pln">common apt</span><span class="pun">-</span><span class="pln">transport</span><span class="pun">-</span><span class="pln">https</span>
第 2 步。在 Debian 11 上安装 Nginx 主线版本。
默认情况下,Nginx 主线在 Debian 11 基础仓库中不可用。所以,现在运行以下命令,将 Nginx 主线仓库添加到你的 Debian 系统中:
<span class="pln">echo </span><span class="str">"deb [arch=amd64,arm64 signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/mainline/debian `lsb_release -cs` nginx"</span> <span class="pun">|</span><span class="pln"> sudo tee </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">apt</span><span class="pun">/</span><span class="pln">sources</span><span class="pun">.</span><span class="pln">list</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">.</span><span class="pln">list</span>
接下来,使用以下命令添加 GPG 密钥:
<span class="pln">curl </span><span class="pun">-</span><span class="pln">fSsL https</span><span class="pun">:</span><span class="com">//nginx.org/keys/nginx_signing.key | sudo gpg --dearmor | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null</span>
设置存储库固定以优先选择我们的包而不是分发提供的包:
<span class="pln">echo </span><span class="pun">-</span><span class="pln">e </span><span class="str">"Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n"</span> <span class="pun">|</span><span class="pln"> sudo tee </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">apt</span><span class="pun">/</span><span class="pln">preferences</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="lit">99nginx</span>
添加存储库后,现在使用以下命令更新包源并安装 Nginx 主线包:
<span class="pln">sudo apt update sudo apt install nginx</span>
安装完成后,启动 Nginx 并将其添加为使用以下方法自动启动系统启动:
<span class="pln">sudo systemctl start nginx sudo systemctl enable nginx</span>
借助以下命令检查已安装的 Nginx 版本:
<span class="pln">nginx </span><span class="pun">-</span><span class="pln">v</span>
第 3 步。配置防火墙。
现在添加防火墙规则以允许连接以及 HTTP(端口 80)和 HTTPS(端口 443)流量:
<span class="nb"><span class="pln">sudo</span></span><span class="pln">ufw allow </span><span class="s1"><span class="str">'Nginx HTTP'</span></span>
感谢您使用本教程在 Debian 11 Bullseye 上安装最新版本的 Nginx Web 服务器。有关其他帮助或有用信息,我们建议您查看Nginx官方网站。