【问题标题】:SPDY with HAProxy and NginxSPDY 与 HAProxy 和 Nginx
【发布时间】:2016-11-12 16:24:53
【问题描述】:

我使用 HAProxy 作为负载平衡器并终止 SSL。在这之后,我放置了一个 Nginx。我想使用 spdy/3.1。

它不适用于以下 haproxy.confnginx.cfg。 (文件是服务器,但根据Chrome SPDY/HTTP2 Indicator Plugin 这只是正常的 HTTP/1.1 流量)。

我试图去掉不必要的部分。

我做错了什么?你有调试技巧吗?

(HAProxy 1.6 当前和 NginX 1.10 稳定线)

haproxy.cfg:

global
  daemon
  tune.ssl.default-dh-param 2048

defaults
  mode tcp

frontend myfrontend
  bind *:80
  bind *:443 ssl crt /etc/ssl/certificate.pem npn spdy/3.1,http/1.1 ciphers ECDH+AESGCM:HIGH:!aNULL:!MD5:!DSS:!RC4; no-sslv3
  acl istoplevel path /
  redirect scheme https if istoplevel !{ ssl_fc }
  redirect location / if !istoplevel !{ ssl_fc }
  rspadd Strict-Transport-Security:\ max-age=31536000;
  default_backend mybackend

backend mybackend
  server s1 localhost:81
  option forwardfor
  http-request set-header X-Forwarded-Port %[dst_port]
  http-request add-header X-Forwarded-Proto https if { ssl_fc }

nginx.conf:

user  nginx;

http {
  include       /etc/nginx/mime.types;
  default_type  application/octet-stream;

  sendfile        on;
  #tcp_nopush     on;

  server {
    listen 81 spdy;
    root /usr/share/nginx/html;
    index index.html;

    location / {
      try_files $uri $uri/ /index.html;
    }
  }
}

【问题讨论】:

  • Nginx 是使用 --with-http_v2-module 构建的。这包括spdy吗?文档对此并不那么冗长

标签: nginx haproxy http2 spdy multiplexing


【解决方案1】:

Chrome 不再支持 SPDY: http://blog.chromium.org/2016/02/transitioning-from-spdy-to-http2.html?m=1

而且它在很多情况下也不支持 HTTP/2:https://ma.ttias.be/day-google-chrome-disables-http2-nearly-everyone-may-31st-2016/

此外,如果您在 HAproxy 上终止,Nginx 正在做什么也没关系。我不确定HAproxy是否支持SPDY?一些帖子建议它does with special config,其他帖子建议它正在等待 HTTP/2。

最终,SPDY 即将退出。当即使它的发明者也不支持它时,你知道你正在打一场失败的战斗。继续使用 HTTP/2 会更好。

【讨论】:

  • 我知道,但是 nodejs 的 http/2 模块的主模块只支持 TLS,因为我在 haproxy 中终止了 ssl,所以我不能使用它
  • nodejs 是从哪里来的!?!原始问题中根本没有提到。那是在 Nginx 后面吗?最终,HAproxy 和 Nginx 之间的连接以及你所拥有的任何其他东西都无关紧要。它的延迟可能非常低,以至于对 HTTP/1.1 的任何好处都将产生微不足道的影响。您关心的是客户端浏览器和 HAProxy 之间的连接 - 使用 SPDY 或最好使用 HTTP/2 来获得最大的好处。顺便说一句,它不需要一直是一个协议,因为一旦您终止 SSL,您也会终止连接并从那时起开始一个新的连接。
  • Nodejs 是除 nginx 之外的另一个服务,它由 haproxy 进行负载均衡。这不是问题的一部分,但当我决定使用 SPDY 时,我考虑到了这一点,这就是我在评论中提到它的原因。好吧,那我会尝试使用 http/2。我认为只有一直使用 SPDY/http2 才有意义 :D 到目前为止谢谢 :) 遇到问题时我会回复你
  • 很好,它成功了。谢谢! :) 现在使用 HTTP/2。不太容易。必须使用 debian:stretch,因为新的 ALPN(Google Chrome 中已放弃 NPN 支持)需要 openssl 1.0.2
【解决方案2】:

您需要为 Chrome 使用 ALPN。对于 HAProxy,您需要 1.8 才能支持使用 HTTP2 终止。

这是来自 CertSimple 的 load balancer with HTTP/2 and dynamic reconfig 指南的 HTTP2 和 ALPN 的相关配置:

frontend public
    # HTTP/2 - see https://www.haproxy.com/blog/whats-new-haproxy-1-8/
    bind :443 ssl crt /etc/https/cert-and-private-key-and-intermediate-and-dhparam.pem alpn h2,http/1.1

【讨论】:

    猜你喜欢
    • 2013-07-21
    • 2012-12-18
    • 2014-03-26
    • 2014-02-06
    • 1970-01-01
    • 2019-08-23
    • 1970-01-01
    • 2016-11-13
    • 2020-09-20
    相关资源
    最近更新 更多