我们有一个 java web 服务器,它能够通过 h2c(HTTP/2 明文)提供内容
我们希望将使用 h2(即基于 SSL 的标准 HTTP/2)建立的代理连接反向到 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
最佳答案
关于java - 将 HTTP/2 从 h2 反向代理到 h2c,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37835445/