【问题标题】:Forward SSL traffic and authentication certificates through HAProxy通过 HAProxy 转发 SSL 流量和身份验证证书
【发布时间】:2020-12-21 07:56:52
【问题描述】:

我有一个来自客户端的 nginx,我可以通过以下方式成功发布:

curl -v --cacert ca.crt --cert client.crt --key client.key -POST https://nginx:8443/api/ -H 'Content-Type: application/json' -H 'cache-control: no-cache' -d@test.json

现在我在 nginx 前面安装了一个 haproxy,我正在尝试以同样的方式进行 POST,但不成功:

curl -v --cacert ca.crt --cert client.crt --key client.key -POST http://haproxy:8443/api/ -H 'Content-Type: application/json' -H 'cache-control: no-cache' -d@test.json

错误:

 <center>The plain HTTP request was sent to HTTPS port</center>
 <hr><center>nginx</center>

这是我的 haproxy 配置:

global
  log         127.0.0.1 local2
  chroot      /var/lib/haproxy
  pidfile     /var/run/haproxy.pid
  maxconn     4000
  user        haproxy
  group       haproxy
  daemon
  stats socket /var/lib/haproxy/stats

defaults
  mode                    tcp
  log                     global
  option                  tcplog
  option                  dontlognull
  option http-server-close
  option forwardfor       except 127.0.0.0/8
  option                  redispatch
  retries                 3
  timeout http-request    10s
  timeout queue           1m
  timeout connect         10s
  timeout client          1m
  timeout server          1m
  timeout http-keep-alive 10s
  timeout check           10s
  maxconn                 3000

frontend  main *:8443
  acl url_static       path_beg       -i /static /images /javascript /stylesheets
  acl url_static       path_end       -i .jpg .gif .png .css .js
  use_backend static          if url_static
  default_backend             app

backend static
  balance     roundrobin
  server      static 127.0.0.1:8443 

backend app
  mode       tcp
  balance     roundrobin
  server  nginx nginx01:8443            

我想通过 HAProxy 转发 SSL 流量并将用于身份验证的证书传递给 nginx。 我知道拥有两个 LB 没有任何意义,但我无法修改 nginx 和后面的 api 服务器,但客户端将是内部的。 正如您在这一点上看到的,我可以访问 nginx,但 haproxy 不会将证书和密钥从请求传递到 nginx 后端。 我错过了什么吗?这是我能做到的吗?

ps:如果我在后端设置“ssl verify none”,我会得到“没有发送所需的 SSL 证书”。 如果我在后端设置“send-proxy”,我会从 nginx 收到“400 Bad Request”。

【问题讨论】:

    标签: ssl nginx haproxy


    【解决方案1】:

    实施的解决方案是使用来自https://www.haproxy.com/documentation/haproxy/deployment-guides/tls-infrastructure/ 的 SS/TLS 直通 将前端和后端都设置为模式 tcp 我能够通过证书和 nginx 验证并进行身份验证。

    【讨论】:

      【解决方案2】:

      您需要将 ssl 配置添加到 haproxy 并设置一些将转发到 nginx 的标头。

      # your other config from above
       
      backend app
        mode       tcp
        balance     roundrobin
        server  nginx nginx01:8443 ssl ca-file <The ca from nginx backend>
      
      

      【讨论】:

        猜你喜欢
        • 2013-08-04
        • 2018-03-06
        • 2019-01-03
        • 1970-01-01
        • 2021-05-20
        • 2010-11-08
        • 2012-06-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多