我有一个来自客户端的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>
这是我的代理配置:
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验证无”,则得到“未发送所需的SSL证书”。 如果我在后端设置“ send-proxy”,那么我将从nginx收到“ 400错误请求”。
答案 0 :(得分:1)
您需要将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>
答案 1 :(得分:0)
实施的解决方案是通过https://www.haproxy.com/documentation/haproxy/deployment-guides/tls-infrastructure/的SS / TLS传递 将前端和后端都设置为tcp模式,我能够通过证书并通过nginx验证并进行身份验证。