是否可以在没有ssl的情况下在NGINX端口443上运行HTTP / 2?

问题描述 投票:0回答:1

我让Envoy代理处理SSL终止。 Nginx(在Docker容器中为1.17.0,已编译--with-http_v2_module)是几种上游服务之一。结果,Nginx在端口443上接收流量,但不使用ssl模块:

server {
    listen 443;
    server_name example.com www.example.com;
    root /var/www/html;

...

这很好,但是如果我尝试在侦听行的末尾添加http2,则会收到:

curl: (1) Received HTTP/0.9 when not allowed

...不仅是有问题的example.com,而且是[[all服务器。

出于明显的性能原因,我希望Envoy通过HTTP / 2与Nginx交谈。

是否有一些技巧可以使nginx在端口443上使用http2而不使用SSL终止?


编辑:

核心nginx.conf

user nginx; worker_processes 2; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; client_max_body_size 64M; sendfile on; keepalive_timeout 65; fastcgi_cache_path /etc/nginx-cache levels=1:2 keys_zone=multipress:100m inactive=60m; fastcgi_cache_key "$scheme$request_method$host$request_uri"; fastcgi_cache_use_stale error timeout invalid_header http_500; fastcgi_ignore_headers Cache-Control Expires Set-Cookie; gzip on; include /etc/nginx/conf.d/*.conf; }

注意,我可以使用显式curl --http2命令成功卷曲当前的Envoy HTTP2服务器。问题是Envoy和Nginx之间的HTTP2连接。
ssl nginx http2 envoyproxy
1个回答
0
投票
Nginx仅支持h2c(这是没有HTTPS的HTTP / 2的称呼,因此您不能使用HTTP / 1.1进行连接然后进行升级。

实际上,如果您尝试使用HTTP / 1.1进行连接,则nginx将错误显示为it doesn’t support HTTP/1.1 and HTTP/2 on the same port unless you are using HTTPS

因此,对于curl,您必须使用此语法直接跳入HTTP / 2:

curl --http2-prior-knowledge localhost:80

[不确定Envoy是否有类似的配置而不使用它,但是如果以上配置适用于curl并且Envoy仍然出现相同的错误,那么至少您已经对Nginx问题有了答案。

但是,我完全不确定是否有必要为您的后端服务器启用h2c,甚至不明智。首先,它会如上所述禁用HTTP / 1.1,并且其他使用HTTP / 1.1的应用程序,服务甚至卷曲测试命令都将中断。

另外the benefits of HTTP/2 at the back end are questionable,主要好处是客户端到服务器的连接,而不是服务器到服务器的后端连接。

© www.soinside.com 2019 - 2024. All rights reserved.