Reputation: 31
Is there any way to support http1.1 upgrade to h2c (not in ssl) in nginx?
use curl test site http://nghttp2.org/
$ curl --http2 http://nghttp2.org/ -s -o /dev/null -v
I get the following result:
* Trying 139.162.123.134...
* TCP_NODELAY set
* Connected to nghttp2.org (139.162.123.134) port 80 (#0)
> GET / HTTP/1.1
> Host: nghttp2.org
> User-Agent: curl/7.54.0
> Accept: */*
> Connection: Upgrade, HTTP2-Settings
> Upgrade: h2c
> HTTP2-Settings: AAMAAABkAARAAAAAAAIAAAAA
>
< HTTP/1.1 101 Switching Protocols
< Connection: Upgrade
< Upgrade: h2c
* Received 101
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=33
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
< HTTP/2 200
< date: Fri, 24 May 2019 08:58:43 GMT
< content-type: text/html
< last-modified: Thu, 18 Apr 2019 06:19:33 GMT
< etag: "5cb816f5-19d8"
< accept-ranges: bytes
< content-length: 6616
< x-backend-header-rtt: 0.009521
< server: nghttpx
< via: 2 nghttpx
< x-frame-options: SAMEORIGIN
< x-xss-protection: 1; mode=block
< x-content-type-options: nosniff
<
{ [2159 bytes data]
* Connection #0 to host nghttp2.org left intact
but when I access a nginx static website , it will fail.
$ curl --http2 -v 10.10.5.89:9006
* Rebuilt URL to: 10.10.5.89:9006/
* Trying 10.10.5.89...
* TCP_NODELAY set
* Connected to 10.10.5.89 (10.10.5.89) port 9006 (#0)
> GET / HTTP/1.1
> Host: 10.10.5.89:9006
> User-Agent: curl/7.54.0
> Accept: */*
> Connection: Upgrade, HTTP2-Settings
> Upgrade: h2c
> HTTP2-Settings: AAMAAABkAARAAAAAAAIAAAAA
>
* Connection #0 to host 10.10.5.89 left intact
$
here is my nginx conf
server {
listen 9006 http2 fastopen=3 reuseport;
location / {
autoindex_exact_size off;
root /www/;
autoindex on;
}
}
}
nginx debug info:
2019/05/24 16:49:53 [debug] 348#348: *1 invalid http2 connection preface "GET / HTTP/1.1
"
2019/05/24 16:49:53 [debug] 348#348: *1 http2 state connection error
2019/05/24 16:49:53 [debug] 348#348: *1 http2 send GOAWAY frame: last sid 0, error 1
2019/05/24 16:49:53 [debug] 348#348: *1 http2 frame out: 0000561508B48B08 sid:0 bl:0 len:8
2019/05/24 16:49:53 [debug] 348#348: *1 http2 frame out: 0000561508B48A58 sid:0 bl:0 len:4
2019/05/24 16:49:53 [debug] 348#348: *1 http2 frame out: 0000561508B489A0 sid:0 bl:0 len:18
Upvotes: 2
Views: 6456
Reputation: 45905
With the --http2
flag and an http:// URL curl sends an HTTP/1.1 message with a request to upgrade to HTTP/2 (upgrade
HTTP header and HTTP2-Settings
HTTP Header) and then upgrades if the site states that it supports HTTP/2 with a 103 response with an upgrade
HTTP header.
That’s what you see happening in the first request for the nghttp2 site, and this only works if the site understands both HTTP/1.1 and HTTP/2.
Your nginx config supports just HTTP/2 and not HTTP/1.1 so this doesn’t work as it doesn’t understand the initial HTTP/1.1 request. Its not possible to make Nginx support both HTTP/1.1 and HTTP/2 on the same port so your config is correct - it just won’t work with that curl command. You need to do this to make curl use HTTP/2 right from the start (called prior knowledge in the HTTP/2 spec - hence the command line option name):
curl --http2-prior-knowledge -v 10.10.5.89:9006
Upvotes: 4