簡體   English   中英

SSL 與遠程服務器握手時出錯

[英]Error during SSL Handshake with remote server

我有Apache2 (監聽 443)和一個 web 應用程序在Ubuntu上運行在Tomcat7 (監聽 8443)上。

I set apache2 as reverse proxy so that I access the web app through port 443 instead of 8443. Besides, I need to have SSL communication not only between browser and apache2 but also between apache2 and tomcat7, thus I set SSL on both apache2 and tomcat7 . 如果我嘗試通過直接聯系 tomcat7 來訪問 web 應用程序,一切都很好。 問題是,當我嘗試通過 apache2(反向代理)訪問 tomcat 的 web 應用程序時,在瀏覽器上出現錯誤:

Proxy Error
The proxy server could not handle the request GET /web_app.
Reason: Error during SSL Handshake with remote server

MK 的評論為我指明了正確的方向。

對於 Apache 2.4 及更高版本,有不同的默認值和新指令。

我正在運行 Apache 2.4.6,我必須添加以下指令才能使其正常工作:

SSLProxyEngine on
SSLProxyVerify none 
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
SSLProxyCheckPeerExpire off

我在 docker、反向代理和 Web 服務器上設置了 2 個服務器。 一年后,我的所有網站突然開始發生此錯誤。 之前設置時,我在 Web 服務器上生成了一個自簽名證書。

所以,我不得不再次生成 SSL 證書並開始工作......

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout ssl.key -out ssl.crt

面臨與 OP 相同的問題:

  • 通過 SOAP UI 直接訪問時 Tomcat 返回響應
  • 未加載 html 文件
  • 使用上一個回答提到的Apache屬性時,出現網頁但AngularJS無法獲得HTTP響應

Tomcat SSL 證書已過期,而瀏覽器顯示它是安全的 - Apache 證書遠未過期。 更新 Tomcat KeyStore 文件解決了這個問題。

我的問題是一台 Apache 服務器落后於另一台服務器,並且每台服務器上的證書不匹配。

我花了一段時間才意識到

SSLCertificateFile

SSLCertificateKeyFile

指向每個服務器上具有相同名稱的文件,但是第一台服務器與第二台服務器相比具有更新的證書和私鑰,因此文件的內容不同。

在遠程 OEL(Oracle Enterprise Linux)7.8 服務器上,我有一個使用 HTTPS/8009 運行的后端 Web 應用程序。 作為第三方應用程序,我無法選擇禁用 SSL 或更改端口。

由於我需要從本地計算機的瀏覽器訪問 Web 應用程序,因此我考慮使用 Apache httpd 設置反向代理(HTTP 到 HTTPS 映射)。 現在我可以通過以下 URL 從本地瀏覽器訪問 Web 應用程序:

http://10.157.146.97:1234/

僅供參考,在 Linux 機器內工作的 CURL 命令如下:

curl http://10.157.146.97:1234/
curl -k https://localhost:8009/

這是我的反向代理設置:

/etc/httpd/conf/httpd.conf

Listen 1234

<VirtualHost *:1234>
SSLProxyEngine On
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
SSLProxyCheckPeerExpire off
ProxyPreserveHost On
ProxyPass / https://localhost:8009/
ProxyPassReverse / https://localhost:8009/
</VirtualHost>

一方面我很掙扎,早些時候我在 ProxyPass/ProxyPassReverse 中嘗試使用 url 模式(/sample),但這導致 css/js 文件出現 HTTP 404(未找到),因為 web 應用程序的歡迎頁面包含間接 css/js 路徑(下面的示例代碼)。 所以用 (/) 替換 url 模式 (/sample) 也解決了這個問題。

previous Not working config:
ProxyPass /sample https://localhost:8009/
ProxyPassReverse /sample https://localhost:8009/

<script defer src="abc.js"></script><link href="xyz.css" rel="stylesheet"></head>  

請注意,當您的系統禁用 TLSv1 時,也可能會發生該錯誤。 例如 Ubuntu 20.x 默認禁用 TLSv1.0。 例如,如果你有這樣的事情:

Apache 2.4.41 on Ubutntu20 (proxy) --[https]--> old Apache serving TLS v1.0

SSLProxyVerify不會幫助你。

您需要做的是在openssl.conf啟用 TLS 1.0。 至少在你可以更新舊服務器之前🙊...

在 Ubuntu 上啟用舊的 TLS

所以在 Ubuntu 20.04.3 TLS 中啟用 TLSv1 更改/etc/ssl/openssl.cnf 在文件頂部(在任何部分之前)添加:

# Added to enable TLS1.0
openssl_conf = default_conf

在文件的最后

##
# Added to enable TLS1.0
[default_conf]
ssl_conf = ssl_sect

[ssl_sect]
system_default = system_default_sect

[system_default_sect]
CipherString = DEFAULT@SECLEVEL=1
##

注釋顯然不是必需的😉,但是當您想再次禁用 TLS1 時會有所幫助。

重新啟動/重新啟動后,一切都應該正常工作。

這是我對這個主題的變體,靈感來自 這個 Git gist 服務器是一個帶有內部自簽名 SSL 證書的 Docker 容器,可通過https://localhost:8443 代理到server.example.org:443 相關配置詳情:

<VirtualHost AAA.BBB.CCC.DDD:443>
    ServerName server.example.org

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # These settings are definitely needed
    SSLEngine On
    SSLProxyEngine On
    ProxyRequests Off
    SSLProxyVerify none 
    SSLProxyCheckPeerCN off
    SSLProxyCheckPeerName off
    SSLProxyCheckPeerExpire off

    # These may not be needed, depending on proxied application
    ProxyPreserveHost on
    RequestHeader set X-Forwarded-Proto https

    ProxyPass "/" "https://localhost:8443/"
    RewriteEngine on
    RewriteCond %{HTTP:Upgrade} websocket [NC]
    RewriteCond %{HTTP:Connection} upgrade [NC]
    RewriteRule ^/?(.*) "wss://localhost:8443/$1" [P,L]
    ProxyPassReverse "/" "https://localhost:8443/"
</VirtualHost>

SSLEngine OnRequestHeader...之間的部分RequestHeader...我通過谷歌搜索和反復試驗組合在一起。 也許不需要這些設置中的一些,YMMV。

注意:需要帶有"wss"RewriteRule ,因為服務器使用安全的 websocket。

平台:Ubuntu 20.04.3 LTS,Apache 2.4.41。

如果您的 apache 代理的主機與代理目標的主機(或其 sni 名稱)不同,請設置 -

ProxyPreserveHost Off

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM