升级网站支持 ALPN

先来回顾一下,浏览器在访问 HTTPS 网站时,如何得知服务端是否支持 HTTP/2?答案是借助 HTTP/2 的协议协商机制:在 HTTP/2 Over HTTP 中,可以使用 HTTP 的 Upgrade 机制进行协商;而对于 HTTP/2 Over TLS,可以使用 TLS 的 NPN 或 ALPN 扩展来完成协商。HTTP/2 的这两种协商方式,不了解的同学请看《谈谈 HTTP/2 的协议协商机制》,这里不再赘述。 当前所有浏览器,都只支持 HTTP/2 Over TLS。也就是说,浏览器和服务端都支持 NPN 或 ALPN 协商,是用上 HTTP/2 的大前提。本文重点讨论 NPN 和 ALPN。 NPN(Next Protocol Negotiation,下一代协议协商),是一个 TLS 扩展,由 Google 在开发 SPDY 协议时提出。随着 SPDY 被 HTTP/2 取代,NPN 也被修订为 ALPN(Application Layer Protocol Negotiation,应用层协议协商)。二者目标一致,但实现细节不一样,相互不兼容。以下是它们主要差别: NPN 是服务端发送所支持的 HTTP 协议列表,由客户端选择;而 ALPN 是客户端发送所支持的 HTTP 协议列表,由服务端选择; NPN 的协商结果是在 Change Cipher Spec 之后加密发送给服务端;而 ALPN 的协商结果是通过 Server Hello 明文发给客户端; 大部分 Web Server 都依赖 OpenSSL 库提供 HTTPS 服务,对于它们来说,是否支持 NPN 或 ALPN 完全取决于使用的 OpenSSL 版本。通常,如果在编译时不特意指定 OpenSSL 目录,Web Server 会使用操作系统内置的 OpenSSL 库。

OpenSSL 1.0.2 才开始支持 ALPN,当前主流服务器操作系统基本都没有内置这个版本。以下是一份粗略的统计(via):

qq20161111143133

//以上摘抄来源:https://imququ.com/post/enable-alpn-asap.html

升级步骤:

环境:centos7+nginx1.10.1

1.通过 OpenSSL 命令行工具,可以快速查看自己的 HTTP/2 服务是否支持 ALPN 扩展:

[root@teddy teddylu]# openssl s_client -alpn h2 -servername teddy -connect teddylu.info:443 < /dev/null | grep ‘ALPN’

执行完上面的的命令,出现unknown option -alpn 表示不支持

2.本站主要使用了 Cloudflare 的 ChaCha20/Poly1305 for OpenSSL 补丁,先来获取补丁文件:
git clone https://github.com/cloudflare/sslconfig.git

2.升级opensll

wget -O openssl.tar.gz -c https://github.com/openssl/openssl/archive/OpenSSL_1_0_2j.tar.gz
tar zxf openssl.tar.gz
mv openssl-OpenSSL_1_0_2j/ openssl

3.打上 ChaCha20/Poly1305 补丁
cd openssl
patch -p1 < ../sslconfig/patches/openssl__chacha20_poly1305_draft_and_rfc_ossl102j.patch

qq20161111140329

安装nginx
 ./configure \
 --prefix=/application/nginx-1.10.1 \
 --with-http_stub_status_module \
 --with-openssl=/root/openssl \
 --with-http_v2_module \
 --with-http_ssl_module \
 --with-http_gzip_static_module \
 --with-http_flv_module \
 --with-http_mp4_module \
 --with-http_realip_module

make但不要make install
。。。。。。剩下的略。如果不懂操作,请看一篇文章nginx如何平滑升级 :

https://teddylu.xyz/archives/3299.html

检查是否升级oepnssl成功
[root@teddy nginx-1.10.1]# /application/nginx-1.10.1/sbin/nginx -V
nginx version: nginx/1.10.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC)
built with OpenSSL 1.0.2j 26 Sep 2016

通过chrome插件查看是否升级成功:

Chrome 插件 “HTTP/2 and SPDY indicator”。这个插件在你访问到一个支持 HTTP/2 (或之前的 SPDY 协议)的网站时会点亮,蓝色flash!!

qq20161111145527

升级网站支持 ALPN
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Scroll to top
0
Would love your thoughts, please comment.x
()
x