概述
我们有一个 .NET Core Web API (.Net 6) 部署为 Azure Web 应用程序,并且我们正在尝试连接到本地 SQL Server。这是非常简单的API。一个端点。它只是连接到我们的本地数据库,检索并返回单个值。
我们采用了完全相同的 API 并部署了它:
- 到通过 Windows 应用服务计划部署的 Azure Web 应用。
- 到使用 Linux 应用服务计划部署的 Azure Web 应用。
我们已将相应 Azure Web API 的出站 IP 列入白名单,以避免防火墙问题。
问题
部署到 Window 应用服务计划的 API 在连接和查询本地数据库时没有问题。但是,当我们尝试连接并运行查询时,部署到 Linux 应用服务计划的相同 API 会导致以下错误:
A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 31 - Encryption(ssl/tls) handshake failed)
有谁知道为什么我们会在 Linux 上而不是 Windows 上遇到问题,以及我们可能需要考虑什么才能允许这两种访问?
相关帖子
- SQL Server Pre-Login Handshake (error: 31 - Encryption(ssl/tls) handshake failed) - 我们在本地支持 TLS 1.2,此外我们的连接字符串指定“TrustServerCertificate=True”
- A connection was successfully established with the server, but then an error occurred during the pre-login handshake - 我们已尝试重新部署应用程序并重新启动应用程序。我们在连接字符串中尝试了“Encrypt=False”,但也没有“Persist Security Info=True”。我们使用的是 Prem 服务器的实际 IP,没有命名。
最佳答案
"Encryption(ssl/tls) handshake failed..."
这意味着别的东西。只需将以下代码添加到 Docker 文件中即可。并首先在本地进行测试。然后您可以尝试使用 Azure。
RUN sed -i 's/MinProtocol = TLSv1.2/MinProtocol = TLSv1/g' /etc/ssl/openssl.cnf
RUN sed -i 's/MinProtocol = TLSv1.2/MinProtocol = TLSv1/g' /usr/lib/ssl/openssl.cnf
RUN sed -i 's/DEFAULT@SECLEVEL=2/DEFAULT@SECLEVEL=1/g' /etc/ssl/openssl.cnf
RUN sed -i 's/DEFAULT@SECLEVEL=2/DEFAULT@SECLEVEL=1/g' /usr/lib/ssl/openssl.cnf
关于asp.net - 从 Linux 应用服务计划中托管的 .NET Core Azure Web 应用连接到 SQL Server 2016 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73694085/