Written by razrlele
14:03 November 5, 2015
在看了一位V友的博文 过后就心里有点痒,午饭的时候就忍不住动手了,整个过程居然还有点小坎坷。。。
首先是得添加Nginx的源:
1 |
sudo vim /etc/apt/sources.list |
添加以下内容:
1 2 |
deb http://nginx.org/packages/mainline/ubuntu/ trusty nginx deb-src http://nginx.org/packages/mainline/ubuntu/ trusty nginx |
这个跟V友博文里面写的不一样,但是我之前按照他写的来添加源有报404,Debian的源Ubuntu估计还是不能直接拿来用。
过后还要下载添加一个证书:
1 |
wget http://nginx.org/keys/nginx_signing.key && sudo apt-key add nginx_signing.key |
然后更新源并重新安装Nginx
1 |
sudo apt-get update && sudo apt-get install nginx |
这里有可能会报错:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: libxslt1.1 nginx-common nginx-core Use 'apt-get autoremove' to remove them. The following packages will be upgraded: nginx 1 upgraded, 0 newly installed, 0 to remove and 9 not upgraded. Need to get 0 B/426 kB of archives. After this operation, 1,050 kB of additional disk space will be used. (Reading database ... 105871 files and directories currently installed.) Preparing to unpack .../nginx_1.9.6-1~trusty_amd64.deb ... Unpacking nginx (1.9.6-1~trusty) over (1.4.6-1ubuntu3.3) ... dpkg: error processing archive /var/cache/apt/archives/nginx_1.9.6-1~trusty_amd64.deb (--unpack): trying to overwrite '/usr/share/nginx/html/index.html', which is also in package nginx-common 1.4.6-1ubuntu3.3 dpkg-deb: error: subprocess paste was killed by signal (Broken pipe) Errors were encountered while processing: /var/cache/apt/archives/nginx_1.9.6-1~trusty_amd64.deb E: Sub-process /usr/bin/dpkg returned an error code (1) |
是跟nginx-common冲突了,所以需要卸载nginx-common
1 |
sudo apt-get remove nginx-common |
然后再安装一遍就OK了。
装好Nginx过后注意要在nginx.conf里面更改用户名,因为Ubuntu源里面的Nginx默认用户是www-data,然后Nginx自己的源里面的默认用户是nginx,如果不改的话瞬间403,印象中之前在本地Archlinux上也碰到过这个问题,当时直接用了服务器上面的Nginx配置文件,然后死命403,我也就奇了怪了,在网上找来找去,各种解决方案都有,就是没人说Nginx用户不一致的问题。
1 |
user www-data; |
然后这个时候Nginx就升级完毕了:
1 2 |
$ nginx -v nginx version: nginx/1.9.6 |
接着就可以开启HTTP/2了,直接修改网站的配置文件:
将
1 |
listen 443; |
改成
1 |
listen 443 ssl http2; |
就可以启动HTTP/2了,过后重启一下Nginx,过户打开浏览器的调试页面就可以看到是否已经是HTTP/2了
速度好像是。。。快了一丢丢。。。