判断某个网站是否支持http2可以在chrome浏览器中安装如下扩展程序
首先要编译--with-http_v2_module模块到nginx中
其次支持https
第三安装nginx http2 协议的客户端工具
yum install nghttp2
server {
server_name www.zhangdazhi.com;
listen 8080 ssl http2;
ssl_certificate conf.d/ssl/2279241_www.zhangdazhi.com.pem;
ssl_certificate_key conf.d/ssl/2279241_www.zhangdazhi.com.key;
root /data/nginx/html;
location / {
http2_push /1.jpg; #当访问根目录时就向客户端退送1.jpg这个文件
}
location /test {
add_header Link "</style.css>;as=style;rel=preload";
http2_push_preload on;
}
}
[root@hk html]#vim test.html
</style.css;as=style;rel=preload> #表示当访问test.html时就会退送根目录下的style.css文件给客户端
测试
[root@hk conf.d]#nghttp -ns https://127.0.0.1:8080/
[WARNING] Certificate verification failed: Hostname mismatch
***** Statistics *****
Request timing:
responseEnd: the time when last byte of response was received
relative to connectEnd
requestStart: the time just before first byte of request was sent
relative to connectEnd. If '*' is shown, this was
pushed by server.
process: responseEnd - requestStart
code: HTTP status code
size: number of bytes received as response body without
inflation.
URI: request URI
see http://www.w3.org/TR/resource-timing/#processing-model
sorted by 'complete'
id responseEnd requestStart process code size request path
13 +536us +108us 427us 200 612 /
2 +8.35ms * +488us 7.86ms 200 2M /1.jpg #当访问根目录时发现退送了1.jpg文件
[root@hk conf.d]#nghttp -ns https://127.0.0.1:8080/test.html
[WARNING] Certificate verification failed: Hostname mismatch
***** Statistics *****
Request timing:
responseEnd: the time when last byte of response was received
relative to connectEnd
requestStart: the time just before first byte of request was sent
relative to connectEnd. If '*' is shown, this was
pushed by server.
process: responseEnd - requestStart
code: HTTP status code
size: number of bytes received as response body without
inflation.
URI: request URI
see http://www.w3.org/TR/resource-timing/#processing-model
sorted by 'complete'
id responseEnd requestStart process code size request path
13 +435us +108us 326us 200 34 /test.html
2 +455us * +384us 70us 404 153 /style.css #当访问test.html时就会退送style.css文件给客户端