Nginx是否支持以明文(h2c)形式从http/1.1升级到http/2

Nginx是否支持以明文(h2c)形式从http/1.1升级到http/2,nginx,http2,nghttp2,Nginx,Http2,Nghttp2,在nginx中有没有办法支持http1.1升级到h2c(不在ssl中) 使用卷曲测试站点 我得到以下结果: * 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: */* &

在nginx中有没有办法支持http1.1升级到h2c(不在ssl中)

使用卷曲测试站点

我得到以下结果:

*   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
这是我的nginx配置


server {
    listen 9006 http2 fastopen=3 reuseport;

    location / {
        autoindex_exact_size off;
        root /www/;
        autoindex on;
        }        
    }
}

nginx调试信息:

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
使用
--http2
标志和http://URL curl发送一条http/1.1消息,请求升级到http/2(
upgrade
http头和
http2设置
http头),然后在站点声明支持http/2时使用带有
upgrade
http头的103响应进行升级

这就是您在对nghttp2站点的第一个请求中看到的情况,只有当站点同时理解HTTP/1.1和HTTP/2时,这才有效

您的nginx配置只支持HTTP/2而不支持HTTP/1.1,因此这不起作用,因为它不理解初始HTTP/1.1请求。因此,您的配置是正确的——它不能与curl命令一起工作。您需要这样做才能使curl从一开始就使用HTTP/2(-因此命令行选项名):

我知道选项--http2先验知识将起作用。只是想确定nginx是否支持http1.1升级到http2。无论如何,谢谢你。

server {
    listen 9006 http2 fastopen=3 reuseport;

    location / {
        autoindex_exact_size off;
        root /www/;
        autoindex on;
        }        
    }
}

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
curl --http2-prior-knowledge -v 10.10.5.89:9006