最近在騰訊雲上配置 nginx 支持 HTTP 2.0 的時候遇到問題html
nginx: [emerg] invalid parameter "http2" in /etc/nginx/sites-enabled/...
nginx -v
查看版本:linux
nginx version: nginx/1.4.6 (Ubuntu)
要升級 nginx 1.9.5 以上才支持 HTTP 2.0nginx
可是經過 apt-get install nginx
並無更新ubuntu
nginx is already the newest version.
看了一下 /etc/apt/sources.list
文件內容全是騰訊雲內部的源,應該是沒有同步最新的版本測試
Google 隨便搜了一個英文博客說要往 sources.list 里加入fetch
deb http://nginx.org/packages/mainline/ubuntu/ codename nginx deb-src http://nginx.org/packages/mainline/ubuntu/ codename nginx
當時無腦就照着加入了,結果 apt-get install nginx
報錯code
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... 上的內容可是並無像原文那樣作說明,其實應該這麼作htm
1 . 先添加源信任簽名文件ip
wget http://nginx.org/keys/nginx_signing.key sudo apt-key add nginx_signing.key
2 . 編輯 /etc/apt/sources.list
在最後加入get
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