Haproxy - HTTP / 2 - TLS ALPN - 无法正常工作

时间:2016-11-18 14:33:00

标签: curl centos7 haproxy http2

我有一台配备OpenSSl 1.0.2j的centos 7服务器。 Nginx正在使用HTTP / 2,但haproxy失败。

当我尝试运行卷曲(已经是版本7.51)一旦启用alpn h2我有以下错误:

curl --http2 -I https://domain:port/file.htm
curl: (16) Error in the HTTP2 framing layer

如果我禁用了h2,curl工作正常但当然只连接http 1.1:

curl --http2 -I https://domain.com:port/file.htm
HTTP/1.1 200 OK
Server: nginx/1.11.6
Date: Fri, 18 Nov 2016 12:22:47 GMT
Content-Type: text/html; charset=utf-8
Last-Modified: Wed, 10 Aug 2016 10:27:58 GMT
Connection: keep-alive
Vary: Accept-Encoding
ETag: "57ab01ae-59"
Expires: Tue, 13 Dec 2016 12:22:47 GMT
Cache-Control: max-age=2160000
X-Page-Speed: Powered By ngx_pagespeed

这里我放了haproxy设置(假设只设置为https模式)

global

  # Default SSL material locations
    ca-base /etc/ssl/certs
    crt-base /etc/ssl/private

    # Default ciphers to use on SSL-enabled listening sockets.
    ssl-default-bind-options   no-sslv3 no-tls-tickets force-tlsv12
    ssl-default-bind-ciphers   ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS

    spread-checks 4

    tune.maxrewrite 1024
    tune.ssl.default-dh-param 2048

...

frontend
    mode tcp
    bind 0.0.0.0:60641 ssl crt /etc/haproxy/certs/domain.pem alpn h2,http/1.1

   http-response set-header Strict-Transport-Security "max-age=16000000; includeSubDomains; preload;"

...

backend

  stick-table type ip size 200k expire 30m
  stick on src

  server server_51_a4.domain.com IP:PORT check ssl verify none

我已经阅读了很多相关的网站和信息

OpenSSL信息:https://www.nginx.com/blog/supporting-http2-google-chrome-users/

设置curl haproxy和其他人:https://blog.cloudflare.com/tools-for-debugging-testing-and-using-http-2/

设置Nginx和Haproxy的最佳网站:http://m12.io/blog/http-2-with-haproxy-and-nginx-guide

这里是Haproxy vv信息

HA-Proxy version 1.7-dev3 2016/05/10
Copyright 2000-2016 Willy Tarreau <willy@haproxy.org>

Build options :
  TARGET  = linux2628
  CPU     = generic
  CC      = gcc
  CFLAGS  = -O2 -g -fno-strict-aliasing -DTCP_USER_TIMEOUT=18
  OPTIONS = USE_LINUX_TPROXY=1 USE_ZLIB=1 USE_REGPARM=1 USE_OPENSSL=1 USE_LUA=1 USE_PCRE=1 USE_PCRE_JIT=1

Default settings :
  maxconn = 2000, bufsize = 16384, maxrewrite = 1024, maxpollevents = 200

Encrypted password support via crypt(3): yes
Built with zlib version : 1.2.7
Compression algorithms supported : identity("identity"), deflate("deflate"), raw-deflate("deflate"), gzip("gzip")
Built with OpenSSL version : OpenSSL 1.0.2j  26 Sep 2016
Running on OpenSSL version : OpenSSL 1.0.2j  26 Sep 2016
OpenSSL library supports TLS extensions : yes
OpenSSL library supports SNI : yes
OpenSSL library supports prefer-server-ciphers : yes
Built with PCRE version : 8.32 2012-11-30
PCRE library supports JIT : yes
Built with Lua version : Lua 5.3.0
Built with transparent proxy support using: IP_TRANSPARENT IPV6_TRANSPARENT IP_FREEBIND

Available polling systems :
      epoll : pref=300,  test result OK
       poll : pref=200,  test result OK
     select : pref=150,  test result OK
Total: 3 (3 usable), will use epoll.

Available filters :
    [COMP] compression
    [TRACE] trace

另外我看到另一个网站告诉haproxy不支持Http / 2.

https://istlsfastyet.com/#server-performance

有什么问题? Haproxy?

Centos 7 openssl支持?

感谢您的阅读。帮助世界为http / 2准备haproxy。

我想添加另一个相关的问题。

“在Web服务器上设置haproxy时,haproxy将进行ALPN协商”。

如果我们可以在两个级别和不同的服务器中使用haproxy会发生什么。

Server 01 - Level 01 - Haproxy ( listen ssl)


Server 02 - Level 02 - Haproxy ( listen ssl)


Server 03 - Level 03 - Nginx  ( listen no ssl )

在这个模型中,谁做过Alpn谈判?

在我的测试中,我试图从SSL创建代理到另一个SSL服务器。

谢谢大家。

Brqx / Ricardo。

1 个答案:

答案 0 :(得分:3)

在Web服务器上预先设置haproxy时,haproxy将进行ALPN协商。这意味着只有haproxy知道协商了哪个协议(http/1.1h2)。我相信你看到一个错误,因为haproxy正在协商h2,然后将明文HTTP / 2流量发送到不期望它的服务器。

正如您所希望的“The complete guide to HTTP/2 with HAProxy and Nginx”网站所指出的那样,您解决的问题是您为两个端口列出了Nginx:一个用于HTTP / 1.1,另一个用于HTTP / 2:

  listen      80  default_server;
  listen      81  default_server http2 proxy_protocol; ## Needed when behind HAProxy with SSL termination + HTTP/2 support

然后,在haproxy中,您声明两个后端:

backend nodes-http
    server node1 web.server:80 check

backend nodes-http2
    mode tcp
    server node1 web.server:81 check send-proxy

并根据协商的ALPN协议指示流量:

use_backend nodes-http2 if { ssl_fc_alpn -i h2 }