
我的客戶端有一個 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' [email protected]
現在我在 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' [email protected]
錯誤:
<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”。
答案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>
答案2
實施的解決方案是透過 SS/TLS 傳遞https://www.haproxy.com/documentation/haproxy/deployment-guides/tls-infrastruct/ 將前端和後端設定為 tcp 模式,我能夠通過證書,nginx 進行驗證並進行身份驗證。