Ssl

Apache反向代理保留ssl

  • November 26, 2020

聯繫方式

我目前通過 VirtualHosts 安裝了多個站點的 Apache。我的目標是慢慢遷移到 dockerized 設置,其中一個 nginx 反向代理將請求分發到 dockerized 應用程序。

為了開始遷移,我在 Apache 設置中創建了一個包羅萬象的內容;對 Apache 不再知道的站點的任何請求都會反向代理到 nginx-proxy docker 容器。然後,我可以在 docker 解決方案中添加一個站點,在 Apache 中禁用它,並且過渡是無縫的。這適用於 http 請求;我遇到了 https 請求的問題。

問題

如何將 apache 設置為不與 https 請求互動,而只從 nginx 傳遞證書和加密數據?只是透明地來回傳遞請求?

client <-- https (nginx signed) --> apache <-- https (nginx signed) --> nginx

其他情況是:

解密並重新簽名: client <-- https (apache signed) --> apache <-- https (nginx signed) --> nginx

後台解密: client <-- https (apache signed) --> apache <-- http --> nginx

這些似乎是可能的,但由於 nginx 服務於多個域,因此 apache 簽名不匹配。此外,如果 Apache 仍需要進行簽名,它對遷移沒有幫助。

目前基本配置

<VirtualHost *:80>

   ServerName example.com

   ProxyPass / http://127.0.0.1:1001/
   ProxyPassReverse / http://127.0.0.1:1001/
   ProxyPreserveHost On

</VirtualHost>

<VirtualHost *:443>

   ServerName example.com

   ProxyPass / https://127.0.0.1:1002/
   ProxyPassReverse / https://127.0.0.1:1002/
   ProxyPreserveHost On

   # These three lines make Apache sign the requests. Without them I
   # generate SSL_ERROR_RX_RECORD_TOO_LONG errors, but with them the
   # response is always signed with the "example.com" certificate
   SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
   SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
   Include /etc/letsencrypt/options-ssl-apache.conf

   # This options seems to make sense but I'm unsure what it does
   SSLProxyEngine On

</VirtualHost>

如果我理解正確,“端點”是指瀏覽器客戶端?(“端點”通常是指 Web 服務端點,而不是服務使用者……)

“經典” HTTPS 甚至不允許您希望發生的情況。主機名通過 DNS 轉換為網路伺服器的 ip:port(443),然後發生 TLS,這在早期確實完全加密了主機名。因此,您的 apache 作為中間人,如果不擁有證書並解密 TLS 流量,將永遠無法找出請求的主機名/域名。

然而。正如經常發生的那樣,成本(有限的公共 IP 範圍)勝過主體安全。因此 TLS 開發了一個名為SNI(編於 2003 年rfc )的擴展,現在許多人都依賴它,它允許伺服器選擇正確的伺服器證書。

我的推薦

…將是,因為您已經提到一切都適用於 HTTP,所以在Apache前面設置一個 nginx作為 https 端點…

endpoint <-- front_nginx signed --> front_nginx <-- HTTP --> Apache <-- HTTP --> target_nginx

…然後將 SSL 遷移作為從 front-nginx 到 target-nginx 的最後一步,然後對 Apache 進行 derezzing。

使用 SNI

如果您想依賴SNI(誠然,您可能已經通過您的虛擬主機設置這樣做了),啟用 mod_proxy_connect 和禁用 SSLProxyEngine 可能就足夠了。最好從 apache 中刪除 SSL 證書,以確保它透明地通過連接進行測試。

這是使用 haproxy 記錄的這種情況:反向代理可以使用 SNI 和 SSL 傳遞嗎?

我從來沒有試過這個,所以我沒有細節。也許我提供的連結可以進一步幫助您。

$$ Edit: $$附錄

(很抱歉進行了多次編輯!)謝謝你的這個問題,它讓我偶然發現了這個:https ://github.com/Lochnair/xt_tls

這可能會解決您的問題並為我啟用一些技巧…

引用自:https://serverfault.com/questions/1043940