解决nginx开启http2不生效问题

先感受一下http2的优势

https://http2.akamai.com/demo

nginx在1.9起就开始支持http2了, 如下配置即可开启

listen 443 ssl http2;
server_name www.koyoz.com koyoz.com;

ssl on;
ssl_certificate fullchain.pem;
ssl_certificate_key privkey.pem;

验证是否开启: Chrome 安装 HTTP/2 and SPDY indicator, 若变成蓝色闪电就表示http2开启了

如果用以上配置后, 仍未开启 那说明编译时openssl的版本太低了. 下载最新openssl-1.0.2h
并指定 –with-openssl 为刚刚下载的新版本, 重新编译nginx, 即可开启https

效果如下:
h2