haproxy中的URL重定向和TCP代理

haproxy中的URL重定向和TCP代理

在一台只有一個 ipv4 並運行 haproxy 的伺服器中,我想重定向一個 url 並在 TCP 層級代理另一個 url,以實現 ssl 直通目的。

frontend https-frontend
  bind *:443
  mode tcp
  option tcplog
  tcp-request inspect-delay 5s
  tcp-request content accept if { req_ssl_hello_type 1 }
  use_backend proxy-backend if { req.ssl_sni -i proxied-url.com }
  redirect prefix https://url-rewrited.com code 301 if  { req.ssl_sni -i domain-for-redirect.com }

但重定向前綴需要http模式,代理透傳需要tcp模式。

[WARNING] 347/153600 (1324) : config : 'redirect' rules ignored for frontend 'https-frontend' as they require HTTP mode.

如果我在 443 中使用兩個前端綁定,則在載入頁面時會發生錯誤。

我該如何繼續?

編輯

我嘗試做一個 http 後端進行重定向

frontend https-frontend
  bind *:443
  mode tcp
  option tcplog
  tcp-request inspect-delay 5s
  tcp-request content accept if { req_ssl_hello_type 1 }
  use_backend proxy-backend if { req.ssl_sni -i proxied-url.com }
  use_backend redirect-backend if  { req.ssl_sni -i domain-for-redirect.com }

backend redirect-backend
  mode http
  option ssl-hello-chk
  redirect prefix https://url-rewrited.com code 301 if { req.ssl_sni -i domain-for-redirect.com }

但是當我訪問domain-for-redirect.com 時,我收到ERR_SSL_PROTOCOL_ERROR。如何在背景載入憑證?

答案1

您需要新增具有有效或自簽章 ssl 憑證的 ssl 選項:改為:bind *:443 使用:bind *:443 ssl crt /etc/ssl/private/certFileName.pem

相關內容