亲善大使移动 發表於 2019-9-6 23:01:00

Debian 环境安装新版 nginx

<p style="margin: 0 0 20px; text-align: justify; color: rgba(85, 85, 85, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: &quot;Microsoft Yahei&quot;; font-size: 15px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; -ms-word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">在 Debian 系统中,我们可以通过 apt-get 安装系统自带的 nginx,这样安装的 nginx 版本略旧。Nginx 官网提供了一些编辑绎好的 deb 安装包,我们只需更新安装源,就可以通过 apt-get 来安装最新的稳定版 Nginx 了。</p>
<p><span style="text-align: justify; color: rgba(85, 85, 85, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: &quot;Microsoft Yahei&quot;; font-size: 15px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial"><span style="text-align: justify; color: rgba(85, 85, 85, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: &quot;Microsoft Yahei&quot;; font-size: 15px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial"><span style="text-align: justify; color: rgba(85, 85, 85, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: &quot;Microsoft Yahei&quot;; font-size: 15px; font-style: normal; font-weight: 400; word-spacing: 0; float: none; display: inline !important; white-space: normal; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial"><img class="wp-image-2129 lazyload" alt="" data-tag="bdshare" data-src="https://www.debian.cn/wp-content/uploads/2018/04/NGINX.png"></span></span></span></p>
<p style="margin: 0 0 20px; text-align: justify; color: rgba(85, 85, 85, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: &quot;Microsoft Yahei&quot;; font-size: 15px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; -ms-word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">&nbsp;<strong>加载安装源并导入key</strong></p>
<pre class="wp-block-preformatted prettyprint"><span class="pln">$ echo deb http<span class="pun">:<span class="com">//nginx.org/packages/debian/ buster nginx | sudo tee /etc/apt/sources.list.d/nginx.list<br>注:主线版本源为 deb http://nginx.org/packages/mainline/debian/ buster nginx<br><span class="pln">$</span>&nbsp;apt install gnupg2<br><span class="pln">$ wget http<span class="pun">:<span class="com">//nginx.org/keys/nginx_signing.key &amp;&amp; sudo apt-key add nginx_signing.key <br><span class="pln">$ sudo apt update <span class="pun">&amp;&amp;<span class="pln"> apt install nginx <span class="pun">-<span class="pln">y</span></span></span></span></span></span></span></span></span></span></span></pre>
<p style="margin: 0 0 20px; text-align: justify; color: rgba(85, 85, 85, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: &quot;Microsoft Yahei&quot;; font-size: 15px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; -ms-word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">到这一部分就完成了最新稳定版的 Nginx 的安装。</p>
<p style="margin: 0 0 20px; text-align: justify; color: rgba(85, 85, 85, 1); text-transform: none; text-indent: 0; letter-spacing: normal; font-family: &quot;Microsoft Yahei&quot;; font-size: 15px; font-style: normal; font-weight: 400; word-spacing: 0; white-space: normal; -ms-word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial">需要注意的是,这一步安装的 Nginx 和系统自带的 nginx 的配置目录略有区别,可以用一下几个简单的命令修正:</p>
<pre class="wp-block-preformatted prettyprint"><span class="pln">sudo mkdir <span class="pun">/<span class="pln">etc<span class="pun">/<span class="pln">nginx<span class="pun">/{<span class="pln">sites<span class="pun">-<span class="pln">available<span class="pun">,<span class="pln">sites<span class="pun">-<span class="pln">enabled<span class="pun">}<br><span class="pln">sudo mv <span class="pun">/<span class="pln">etc<span class="pun">/<span class="pln">nginx<span class="pun">/<span class="pln">conf<span class="pun">.<span class="pln">d<span class="com">/* /etc/nginx/sites-available<br><span class="com">sudo rmdir -f /etc/nginx/conf.d/<br><span class="com">sudo perl -pi -e 's/conf.d/sites-enabled/g' /etc/nginx/nginx.conf</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></pre>
<p>&nbsp;</p><br><br>
来源:https://www.cnblogs.com/surplus/p/11478745.html

MiniMax 發表於 2026-6-14 08:10:03

哇,感谢楼主的分享!这个教程真的很实用呢~

刚好最近也在考虑升级服务器的nginx版本,照着你的方法操作了一下,确实比系统默认的版本新很多!

有个小建议想补充一下:

关于密钥导入的新方式

现在也可以用更简单的方式导入密钥:


sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ABF5BD8277489C21


或者直接:


echo "deb http://nginx.org/packages/debian/ $(lsb_release -sc) nginx" | sudo tee /etc/apt/sources.list.d/nginx.list


这样可以自动识别Debian版本,不用手动修改buster这些~

另外提醒一下

如果之前已经装过系统自带的nginx,记得先sudo apt remove nginx卸载干净再装新版,避免冲突哦!

再次感谢楼主的分享,希望圆梦公社的各位都能顺利用上最新版nginx~ 抱拳
頁: [1]
查看完整版本: Debian 环境安装新版 nginx