Ubuntu 14.04 升级 nginx 遇到的问题

最近在腾讯云上配置 Nginx 支持 HTTP 2.0 的时候遇到问题

Nginx: [emerg] invalid parameter "http2" in /etc/Nginx/sites-enabled/...

Nginx -v 查看版本:

Nginx version: Nginx/1.4.6 (Ubuntu)

升级 Nginx 1.9.5 以上才支持 HTTP 2.0

但是通过 apt-get install Nginx 并没有更新

Nginx is already the newest version.

看了一下 /etc/apt/sources.list 文件内容全是腾讯云内部的源,应该是没有同步最新的版本

Google 随便搜了一个英文博客说要往 sources.list 里加入

deb http://Nginx.org/packages/mainline/ubuntu/ codename Nginx
deb-src http://Nginx.org/packages/mainline/ubuntu/ codename Nginx

当时无脑就照着加入了,结果 apt-get install Nginx 报错

Err http://Nginx.org codename/Nginx Sources
  404  Not Found [IP: 206.251.255.63 80]
Err http://Nginx.org codename/Nginx amd64 Packages
  404  Not Found [IP: 206.251.255.63 80]
Err http://Nginx.org codename/Nginx i386 Packages
  404  Not Found [IP: 206.251.255.63 80]
Ign http://Nginx.org codename/Nginx Translation-en
W: Failed to fetch http://Nginx.org/packages/debian/dists/codename/Nginx/source/Sources  404  Not Found [IP: 206.251.255.63 80]
...

后来才发现原来那个博客直接抄了 http://nginx.org/en/linux_pac... 上的内容但是并没有像原文那样做说明,其实应该这么做

1 . 先添加源信任签名文件

wget http://Nginx.org/keys/Nginx_signing.key
sudo apt-key add Nginx_signing.key

2 . 编辑 /etc/apt/sources.list 在最后加入

deb http://Nginx.org/packages/ubuntu/ trusty Nginx
deb-src http://Nginx.org/packages/ubuntu/ trusty Nginx

其中,这个没有包含 mainline 的地址是稳定版(推荐用稳定版,当然加上 mainline 保持最新也无所谓);trusty 是 Ubuntu 14.04 的代号,其他版本或者系统就要自己去 http://nginx.org/en/linux_pac... 看了

3 . 可以安装了

sudo apt-get update
sudo apt-get clean && apt-get install Nginx

4 . 如果再次按照遇到这个错误

Unpacking Nginx (1.10.2-1~trusty) over (1.4.6-1ubuntu3.7) ...
dpkg: error processing archive /var/cache/apt/archives/Nginx_1.10.2-1~trusty_amd64.deb (--unpack):
 trying to overwrite '/etc/default/Nginx',which is also in package Nginx-common 1.4.6-1ubuntu3.7
dpkg-deb: error: subprocess paste was killed by signal (broken pipe)

可以先删除之前的版本再安装,删除之前注意备份 /etc/Nginx/ 下的配置文件

sudo apt-get purge Nginx Nginx-common
sudo apt-get clean && apt-get install Nginx

5 . 最后把配置文件恢复(可以用 Nginx -t 测试一下配置文件是否正确),然后就可以启动了

sudo service Nginx start

相关文章

目录前言一、创建Hadoop用户二、更新apt和安装Vim编辑器三、...
原文连接:https://www.cnblogs.com/yasmi/p/5192694.html ...
电脑重启后,打开VirtualBox,发现一直用的虚拟机莫名的消失...
参见:https://blog.csdn.net/weixin_38883338/article/deta...
Ubuntu 18.04 LTS 已切换到 Netplan 来配置网络接口。Netpla...
介绍每个 Web 服务都可以通过特定的 URL 在 Internet 上访问...