最近在腾讯云上配置 Nginx 支持 HTTP 2.0 的时候遇到问题
Nginx -v
查看版本:
要升级 Nginx 1.9.5 以上才支持 HTTP 2.0
但是通过 apt-get install Nginx
并没有更新
- Nginx is already the newest version.
看了一下 /etc/apt/sources.list
文件内容全是腾讯云内部的源,应该是没有同步最新的版本
Google 随便搜了一个英文博客说要往 sources.list 里加入
当时无脑就照着加入了,结果 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... 上的内容但是并没有像原文那样做说明,其实应该这么做
2 . 编辑 /etc/apt/sources.list
在最后加入
其中,这个没有包含 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/
下的配置文件
5 . 最后把配置文件恢复(可以用 Nginx -t
测试一下配置文件是否正确),然后就可以启动了
- sudo service Nginx start