1、HTTP 2.0简介
HTTP/2 (原名HTTP/2.0)即超文本传输协议 2.0,是下一代HTTP协议。是由互联网工程任务组(IETF)的Hypertext Transfer Protocol Bis (httpbis)工作小组进行开发。是自1999年http1.1发布后的首个更新。HTTP 2.0在2013年8月进行首次合作共事性测试。目前在开放互联网上HTTP 2.0将只用于https://网址,而http://网址将继续使用HTTP 1.1。
2、HTTP 2.0 优点
HTTP2.0大幅度的提高了web性能,在HTTP1.1完全语意兼容的基础上,进一步减少了网络的延迟。实现低延迟高吞吐量。对于前端开发者而言,减少了优化工作。有以下优点
二进制分帧
首部压缩
流量控制
多路复用
请求优先级
服务器推送
二、前提条件
1、openssl的版本必须在1.0.2e及以上,在 Chrome 51后,谷歌去掉了对 NPN 的支持,HTTP2不能用了会证书错误,而openssl1.0.2e之后的版本修复了此问题
2、开启https加密,目前http2.0只支持开启了https的网站
3、nginx的版本必须在1.9.5以上,原因是nginx从1.9.5开始,已经用 http_v2_module 模块替换了 ngx_http_spdy_module
4.nginx必须安装with-http_v2_module模块
检查openssl版本
[root@blog ~]# openssl version
OpenSSL 1.0.2k-fips 26 Jan 2017
检查nginx是否安装with-http_v2_module模块
[root@blog ~]# nginx -V|grep -o ‘with-http_v2_module’
with-http_v2_module
如以上没要安装请自行百度进行安装
配置nginx
[root@blog ~]# cat default.conf
server {
listen 80;
server_name yeyouqing.top;
rewrite ^/(.*) https://www.yeyouqing.top/$1 permanent;
access_log off;
}
server {
listen 80;
server_name www.yeyouqing.top;
rewrite ^/(.*) https://www.yeyouqing.top/$1 permanent;
access_log off;
}
server {
listen 443 ssl http2; #此处加上http2,即可开启http2协议,必须在443端口配置,无法在80端口配置
server_name www.yeyouqing.top;
root /usr/share/nginx/html/wordpress;
ssl_certificate /usr/share/nginx/html/wordpress/ssl/1_www.yeyouqing.top_bundle.crt;
ssl_certificate_key /usr/share/nginx/html/wordpress/ssl/2_www.yeyouqing.top.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_session_cache shared:sslcache:20m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_session_timeout 5m;
index index.php index.html index.htm index.nginx-debian.html;
location ~ \.php$ {
fastcgi_index index.php;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$ {
expires 7d;
access_log off;
}
location ~ ^/(\.user.ini|\.ht|\.git|\.svn|\.project|LICENSE|README.md) {
deny all;
}
}
使用火狐浏览器检查

写的不错,加油
Thank you!!1
写的不错