目前
chrome,firefox都已支持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的客户端程序,类似于wgetnghttpx 一个http/2.0的代理程序, 类似于squidnghttpd 一个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,也可以使用不带ssl的http/2.0,命令如下nghttpx -f '0.0.0.0,80' -b 127.0.0.1,81 --frontend-notls
当然了,
nghttpx/nghttpd也支持http/1.1,http/1.0协议,完全不用担心不支持http/2.0的浏览器。
更多关于nghttp2的信息点击这里.