
nginx 新增了 http_v2_module 模块用于提供 http/2 服务,这个模块是以 patch 形式提供。官方对此有三点说明:
强烈不建议用于生产环境;
现阶段不支持 server push;
这个 patch 会替换之前的 spdy 模块,也就是说应用 patch 后不能再给站点配置 spdy;
介绍完基本信息,下面简单写下如何让 nginx 支持 http/2:
接着,进入解压好的 nginx 源码目录,下载并应用补丁:
<code>cd nginx-1.9.3</code>
<code>wget http://nginx.org/patches/http2/patch.http2.txt</code>
<code>patch -p1 < patch.http2.txt</code>
配置时,至少需要启用 http_v2_module 和 http_ssl_module 这两个模块:
<code>./configure --with-openssl=../libressl-2.2.2 --with-http_v2_module --with-http_ssl_module</code>
然后 <code>make</code> 并 <code>make install</code> 就搞定了。在 nginx 配置中启用站点对 http/2 的支持也很方便,只需要在 <code>listen</code> 时加上 <code>http2</code> 就可以了,例如:
<code>listen 443 ssl http2 fastopen=3 reuseport;</code>
其他的配置之前的文章都写过,这里不重复了。另外,由于 http/2 并不会使用 gzip 来压缩头部,之前用于 spdy 的 <code>spdy_headers_comp</code> 配置已经不需要了,也就是说不会有类似于 <code>http2_headers_comp</code> 的配置。
经过一天的简单试用,我发现 nginx 这个 http/2 补丁的稳定性还可以,所以先这样用着,后续有什么发现再补充。
本文来自云栖社区合作伙伴“linux中国”,原文发布日期:2015-08-21