gpt4 book ai didi

azure - Azure Web App 和 Azure SQL Server 的 VNet 集成

转载 作者:行者123 更新时间:2023-12-04 09:42:11 26 4
gpt4 key购买 nike

我有一个 Azure Web App 和一个 Azure SQL Server,它们都位于同一订阅中。它们都连接到同一 VNet 子网,如下面的快照所示。 SQL Server 配置为不允许 Azure 资源和服务访问服务器,因为它应该只允许来自连接的子网或一组 IP 规则的访问。

不幸的是,SQL Server 主动拒绝来自 Web 应用程序的任何连接,指出不允许 Web 应用程序 IP 访问服务器。

有趣的是,我在另一个订阅上有完全相同的配置。

我可能会错过什么?

快照:

1- 在这里您可以看到连接到“webapps”子网的 Web 应用程序

enter image description here

2-在这里您可以看到连接到同一子网的 SQL Server

enter image description here

3- 这就是我得到的错误

enter image description here

最佳答案

TLDR

配置正确,但可能需要重新启动应用服务。

VNET 集成

使用虚拟网络将 Web 应用程序连接到 SQL 数据库的配置正确:如果 Web 应用程序连接到数据库 ACL 中允许的同一子网/vnet,在子网上启用了 Microsoft.Sql 服务终结点,Web 应用程序能够与数据库进行通信。这就是服务端点的全部原因:您不需要在数据库上配置 IP 限额。

至于为什么配置仍然出错,可能是资源配置顺序的问题。我们遇到了完全相同的设置和问题(这就是让我提出这个问题的原因)!

我们将 Web 应用程序连接到子网/vnet,但尚未在子网上启用服务终结点。然后,我们在数据库中添加/允许子网/vnet 作为 ACL,在此期间系统提示我们启用 Microsoft.Sql 服务端点(我们确实这样做了)。然而,即使等待了大约 20 分钟,我们仍然看到相同的连接问题。

但是,一旦我们重新启动应用服务,问题就消失了,并且 Web 应用可以连接到 SQL 数据库。

我怀疑该问题是由于在应用服务连接到子网后启用子网的服务端点而导致的。应用服务必须需要重新启动才能刷新应用服务的 vnet 配置/路由。

不需要配置

与其他答案相反,您不需要配置防火墙 IP 限额,也不需要启用对 Azure 服务和资源的访问。事实上,这两种方法都有缺点:

  • 启用对 Azure 服务和资源的访问允许任何基于 Azure 的资源连接到您的数据库,其中包括不属于您的资源。来自 doc :

    This option configures the firewall to allow all connections from Azure, including connections from the subscriptions of other customers.

  • 除非您使用应用服务环境(比普通应用服务计划贵得多),否则您的网络应用的出站 IP 地址既不是静态的,也不是特定于您的应用的。来自 doc :

    Azure App Service is a multi-tenant service, except for App Service Environments. Apps that are not in an App Service environment (not in the Isolated tier) share network infrastructure with other apps. As a result, the inbound and outbound IP addresses of an app can be different, and can even change in certain situations.

第二点在this Github issue中有进一步阐述。 :

IPs are indeed shared with other App Service plans (including other customer's plans) that are deployed into the same shared webspace. The network resources are shared among the plans in a workspace even if the computing instances are dedicated (e.g. in Standard tier). This is inherent to the App Service multi-tenant model. The only way to have a dedicated webspace (i.e. outbound IPs) is to deploy an App Service plan into an App Service Environment (ASE) (i.e. Isolated tier). ASE is the only thing that offers true single-tenency in App Service.

因此,如果您只想隔离与 Web 应用程序的通信,则以上选项都不会真正强化您的 SQL 数据库。如果您的资源位于同一子网中,那么使用 vnet 集成是解决问题的正确方法。

如果资源不能位于同一子网中,解决方案是使用 Private Endpoints .

关于azure - Azure Web App 和 Azure SQL Server 的 VNet 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62276437/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com