我已经安装了httpd-2.4.18和nghttp 1.6.0以及curl 7.46来处理http2服务器。当我用Curl和nghttp命令测试它时,服务器似乎可以使用http2(如下所示),但是当我使用浏览器(谷歌浏览器47.0.2526.106)时,响应头是http1而不是http2,而Spdy指示灯为灰色(应为蓝色)。有人知道为什么吗?
使用curl命令说我http2正常工作:
eloy@eloy-OptiPlex-745:/usr/local/apache2/logs$ curl --http2 -I http://localhost
HTTP/1.1 101 Switching Protocols
Upgrade: h2c
Connection: Upgrade
HTTP/2.0 200
date:Thu, 07 Jan 2016 21:38:06 GMT
server:Apache/2.4.18 (Unix) OpenSSL/1.0.2e
last-modified:Mon, 11 Jun 2007 18:53:14 GMT
etag:"2d-432a5e4a73a80"
accept-ranges:bytes
content-length:45
content-type:text/html
与nghttp2相同,似乎http2服务器正常使用以下命令:
eloy@eloy-OptiPlex-745:/usr/local/apache2/logs$ nghttp -uv http://localhost
[ 0.000] Connected
[ 0.000] HTTP Upgrade request
GET / HTTP/1.1
host: localhost
connection: Upgrade, HTTP2-Settings
upgrade: h2c
http2-settings: AAMAAABkAAQAAP__
accept: */*
user-agent: nghttp2/1.6.0
[ 0.001] HTTP Upgrade response
HTTP/1.1 101 Switching Protocols
Upgrade: h2c
Connection: Upgrade
[ 0.001] HTTP Upgrade success
[ 0.001] recv SETTINGS frame <length=6, flags=0x00, stream_id=0>
来自浏览器的响应标头:
HTTP/1.1 304 Not Modified
Date: Thu, 07 Jan 2016 21:49:40 GMT
Server: Apache/2.4.18 (Unix) OpenSSL/1.0.2e
Connection: Upgrade, Keep-Alive
Keep-Alive: timeout=5, max=100
ETag: "2d-432a5e4a73a80"
从浏览器请求标头:
GET / HTTP/1.1
Host: localhost
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: es-ES,es;q=0.8
If-None-Match: "2d-432a5e4a73a80"
If-Modified-Since: Mon, 11 Jun 2007 18:53:14 GMT
答案 0 :(得分:2)
浏览器不支持HTTP / 1.1到HTTP / 2升级请求。
从浏览器使用HTTP / 2的唯一方法是通过TLS和ALPN。
话虽如此,您的#34;来自浏览器的请求标头&#34;上面实际上是响应标题,反之亦然,所以很难说出你实际在做什么。请求标头缺少必要的升级位。
如果您从浏览器发出明文请求(即使用http
方案),则浏览器不会尝试升级,您将保持HTTP / 1.1模式。