0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

为 Nginx 添加 http2 支持

Last updated at Posted at 2016-01-01

今年5月份吧...好像是, HTTP/2 的协议正式版出来了. 替代了之前一直是测试的spdy的协议

下面我们来为nginx添加这个协议的支持.
本文章是使用 Tengine的这个nginx的mod 版本来做的.
首先从 github 上下载源码

git clone https://github.com/alibaba/tengine.git

然后在 configure的时候需要加2个配置参数

./configure --with-http_ssl_module --with-http_v2_module

编译完成后执行如下命令确认是否包含http2的模块

objs/nginx -V

如果ngx_http_v2_module (static) 这么一行内容那就说明已经成功了.

最后需要在虚拟主机的配置文件里把原来的

listen 443 ssl

改成

listen 443 ssl http2 fastopen=3 reuseport

就可以了. 注意 http2 这个关键字只需要在所有 linsten 443 ssl 里出现一次即可 负责会报 配置重复.
最后

service nginx reload 

就可以了.
然后尝试访问下 你的 https的网站吧.

PS: 如果 Chrome 出现了 ERR_SPDY_INADEQUATE_TRANSPORT_SECURITY 的错误的话,

  • 请检查 配置文件的 ssl_ciphers 节点. 可能需要修改为如下的值
ssl_ciphers 'CHACHA20:EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH:ECDHE-RSA-AES128-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA128:DHE-RSA-AES128-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-GCM-SHA128:ECDHE-RSA-AES128-SHA384:ECDHE-RSA-AES128-SHA128:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES128-SHA128:DHE-RSA-AES128-SHA128:DHE-RSA-AES128-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA384:AES128-GCM-SHA128:AES128-SHA128:AES128-SHA128:AES128-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4;';
ssl_prefer_server_ciphers on;
  • 可能是weak dhparam 的问题.需要生成一个 2048 位的 dhparam 然后配置下.
openssl dhparam -out dhparams.pem 2048

然后 在nginx配置文件里添加

ssl_dhparam {path to dhparams.pem}

最后重新加载下 nginx 就可以大功告成了

参考文档

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?