【问题标题】:Reverse proxying HTTP/2 from h2 to h2c将 HTTP/2 从 h2 反向代理到 h2c
【发布时间】:2016-10-16 13:39:37
【问题描述】:

我们有一个 java web 服务器,它能够通过 h2c(HTTP/2 明文)提供内容

我们希望将使用 h2(即标准 HTTP/2 over SSL)建立的代理连接反向到 h2c 中的 java 服务器。

在 nginx 上启用 HTTP/2 非常简单,并且处理传入的 h2 连接工作正常。

我们如何告诉 nginx 使用 h2c 而不是 http/1.1 代理连接?

注意:非 nginx 解决方案可能是可以接受的

server {
    listen       443 ssl http2 default_server;
    server_name  localhost;

    ssl_certificate      /opt/nginx/certificates/???.pem;
    ssl_certificate_key  /opt/nginx/certificates/???.pk8.key.pem;

    ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;

    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers  on;

    location / {
        proxy_pass http://localhost:8080/;  ## <---- h2c here rather than http/1.1
    }
}

结论(2016 年 6 月)

这可以通过 haproxy 使用如下简单的配置文件来完成。

查询(HttpServletRequest)req.getProtocol()明显返回HTTP/2.0

global
tune.ssl.default-dh-param 1024

defaults
timeout connect 10000ms
timeout client 60000ms
timeout server 60000ms

frontend fe_http
mode http
bind *:80
# Redirect to https
redirect scheme https code 301

frontend fe_https
mode tcp
bind *:443 ssl no-sslv3 crt mydomain.pem ciphers TLSv1.2 alpn h2,http/1.1
default_backend be_http

backend be_http
mode tcp
server domain 127.0.0.1:8080

【问题讨论】:

  • 我猜 nginx 不支持。 nginx.org/r/proxy_http_version
  • @AlexeyTen 希望它尽快完成.. 同时使用 haproxy
  • 我会查询其中的值。 HTTP/2 的主要好处是用于高延迟的客户端-服务器连接,而对于低延迟的服务器-服务器连接来说则更少。 HTTP/2 将是大多数连接(最终包括服务器到服务器的连接)的未来,但目前缺乏支持说明这是多么新,因此基于有限的优势转向该协议是否明智.只是我的看法——顺便说一句,我是 HTTP/2 的忠实拥护者,所以不要试图低估那里的好处。

标签: java nginx reverse-proxy haproxy http2


【解决方案1】:

HAProxy 确实支持。

HAProxy 可以卸载 TLS 并转发到使用 h2c 的后端。

this blog post 中提供了有关如何设置此配置的详细信息。

【讨论】:

  • 谢谢。现在正在尝试。我会报告结果
  • @BrunoGrieder,出于好奇,说h2c 的后端服务器是什么?
  • 我们使用 Jetty Embedded 9.3.9
  • @sbordet 您能否提供一个 HAproxy 配置示例,其中使用 http 模式将 h2c 请求发送到后端。我在尝试使用proto h2 时遇到了以下问题:discourse.haproxy.org/t/…
猜你喜欢
  • 2018-07-12
  • 2018-12-13
  • 2016-12-08
  • 2017-07-10
  • 1970-01-01
  • 1970-01-01
  • 2016-09-30
  • 1970-01-01
  • 2015-05-05
相关资源
最近更新 更多