2015年3月28日星期六

让你的web server支持http/2.0

http/2.0 是下一代的http协议(查看wikipedia),它 比http/1.1具有更高的效率,目前还没有正式发布,还处在修改阶段,新最的标准是draft-17h2-17.
目前chromefirefox都已支持http/2.0了,我们可以在自己的网站上部署http/2.0来尝新。
我们可以使用这个C语言的http/2.0的库nghttp2, 安装方法:
git clone https://github.com/tatsuhiro-t/nghttp2
cd nghttp2
autoreconf -ivf
./configure
make
sudo make install
安装成功后,有如下组件:
libnghttp2-xx.so 解析http/2.0的协议的库文件
nghttp 一个http/2.0的客户端程序,类似于wget
nghttpx 一个http/2.0的代理程序, 类似于squid
nghttpd 一个http/2.0的web server程序, 类似于nginx
如果你的web server只有静态文件, 使用nghttpd就够了
nghttpd -d /path/to/docroot 443 server.key server.crt
如果不用ssl
nghttpd -d /path/to/docroot 80 --no-tls
如果要支持php等动态内容,你可以使用nghttpx作为前端,后端使用nginx或者apache, 像这样
nghttpx -f '0.0.0.0,443' -b 127.0.0.1,81 --cert server.crt --key server.key
nghttpx监听443端口,接收http/2.0请求,然后转发到127.0.0.1:81端口,让apache运行在此81端口处理实际的请求。
nghttpx黙认是启用ssl的,如果你的网站没有部署ssl,也可以使用不带sslhttp/2.0,命令如下
nghttpx -f '0.0.0.0,80' -b 127.0.0.1,81 --frontend-notls
当然了,nghttpx/nghttpd也支持http/1.1http/1.0协议,完全不用担心不支持http/2.0的浏览器。
如果你安装了spdylay库, 在启用ssl时,nghttpd/nghttpx也支持spdy/3.1协议。
更多关于nghttp2的信息点击这里.

没有评论:

发表评论