HTTP 2.0即超文本传输协议 2.0,是下一代HTTP协议。是由互联网工程任务组(IETF)的Hypertext Transfer Protocol Bis (httpbis)工作小组进行开发。是自1999年http1.1发布后的首个更新。 HTTP/2 协议是从 SPDY 演变而来,SPDY 已经完成了使命并很快就会退出历史舞台(例如 Chrome 将在「2016 年初结束对 SPDY 的支持」;Nginx、Apache 也已经全面支持 HTTP/2 ,并也不再支持 SPDY)。一般的大家把 HTTP2 简称为 h2,尽管有些朋友可能不怎么愿意,但是这个简称已经默认化了,特别是体现在浏览器对 HTTP2 都是这个简写的。普通的 HTTPS 网站浏览会比 HTTP 网站稍微慢一些,因为需要处理加密任务,而配置了 h2 的 HTTPS,在低延时的情况下速度会比 HTTP 更快更稳定!
准备工作:
1.要开启HTTP/2需要nginx版本在1.10.0以上且需要openssl版本在1.0.2以上编译。
2.http2.0只支持开启了https的网站
1.安装openssl-1.1.0c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 cd /root wget https: tar -zxf openssl-1.1 .0c.tar.gz cd openssl-1.1 .0c ./config make make install #把旧版本的openssl重命名 mv /usr/ bin/openssl / usr/bin/ openssl.bak mv /usr/ include/openssl / usr/include/ openssl.bak #设置软连接指向刚编译好的新版本的openssl-1.1 .0c ln -s /usr/ local/bin/ openssl /usr/ bin/openssl ln -s /usr/ local/include/ openssl /usr/ include/openssl #如果是1.0 .2h版本 生成的文件的位置在/usr/ local/ssl #添加libssl.so.1.1的软链接 ln -s /usr/ local/lib64/ libssl.so.1.1 /usr/ lib64/libssl.so.1.1 ln -s /usr/ local/lib64/ libcrypto.so.1.1 /usr/ lib64/libcrypto.so.1.1 #查看openssl版本 openssl version
2.平滑升级nginx到最新的稳定版 查看现在的nginx版本和编译参数
1 2 3 4 5 6 [root@sf3 ~] nginx version: nginx/1.10 .0 built by gcc 4.4 .7 20120313 (Red Hat 4.4 .7 -17 ) (GCC) built with OpenSSL 1.0 .1 e-fips 11 Feb 2013 TLS SNI support enabled configure arguments: --user= www --group= www --prefix= /usr/local/nginx --with -http_stub_status_module --with -http_ssl_module --with -http_v2_module --with -http_gzip_static_module --with -ipv6 --with -http_sub_module
最新稳定版本是1.10.2,官网地址:http://nginx.org
升级步骤
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 cd /root wget http://nginx.org/download/nginx-1.10 .2 .tar.gz tar zxvf nginx-1.10 .2 .tar.gz cd nginx-1.10 .2 ./configure --user= www --group= www --prefix= /usr/local/nginx --with -http_stub_status_module --with -http_ssl_module --with -http_v2_module --with -http_gzip_static_module --with -ipv6 --with -http_sub_module --with-openssl= /root/openssl-1.1 .0 c make mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old cp objs/nginx /usr/local/nginx/sbin/ make upgrade nginx -V
3.配置http2.0 配置Nginx开启http 2.0特别简单,只要在Nginx配置文件中找到你要开启http2.0的域名server模块,然后将 listen 443 ssl;改成 listen 443 ssl http2; 即可。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 server { listen 443 ssl http2; server_name domain.com; ssl_certificate /path/to/public.crt; ssl_certificate_key /path/to/private.key; ssl_protocols TLSv1 TLSv1 .1 TLSv1 .2 ; ssl_ciphers EECDH +CHACHA20 :EECDH+AES128 :RSA+AES128 :EECDH+AES256 :RSA+AES256 :EECDH+ 3 DES: RSA +3 DES: !MD5 ; ssl_prefer_server_ciphers on; ssl_session_timeout 10 m; ssl_session_cache builtin: 1000 shared: SSL : 10 m; ssl_buffer_size 1400 ;
保存配置文件之后,重启或重载Nginx即可生效:/usr/local/nginx/sbin/nginx -s reload
要验证http2是否生效可以安装个chrome插件HTTP/2 and SPDY indicator,如果开启了h2,那么会有一道蓝色的闪电。 要优化nginx配置可以用https://mozilla.github.io/server-side-tls/ssl-config-generator/这个生成的配置。
我这个博客https://fazero.me就开启了http2。
参考链接:https://zhangge.net/4856.html http://www.cnblogs.com/songqingbo/p/5464620.html http://www.cnblogs.com/xyb930826/p/6077348.html