有关 Azure Functions 中的网络的常见问题解答Frequently asked questions about networking in Azure Functions

本文列出了有关 Azure Functions 中的网络的常见问题解答。This article lists frequently asked questions about networking in Azure Functions. 有关更完整的概述,请参阅 Functions 网络选项For a more comprehensive overview, see Functions networking options.

如何在 Functions 中设置静态 IP?How do I set a static IP in Functions?

目前,在应用服务环境中部署函数是为函数提供静态入站和出站 IP 的唯一方法。Deploying a function in an App Service Environment is currently the only way to have a static inbound and outbound IP for your function. 有关如何使用应用服务环境的详细信息,请从在应用服务环境中创建和使用内部负载均衡器一文着手。For details on using an App Service Environment, start with the article Create and use an internal load balancer with an App Service Environment.

如何限制对我的函数的 Internet 访问?How do I restrict internet access to my function?

可以采用多种方式来限制 Internet 访问:You can restrict internet access in a couple of ways:

  • IP 限制:按 IP 范围限制到您的函数应用的入站流量。IP restrictions: Restrict inbound traffic to your function app by IP range.
    • 在 IP 限制下,你还能够配置服务终结点,这会将您的函数限制为仅接受来自特定虚拟网络的入站流量。Under IP restrictions, you are also able to configure Service Endpoints, which restrict your Function to only accept inbound traffic from a particular virtual network.
  • 删除所有 HTTP 触发器。Removal of all HTTP triggers. 对于某些应用程序,只需要避免使用 HTTP 触发器并使用任何其他事件源来触发您的函数就足够了。For some applications, it's enough to simply avoid HTTP triggers and use any other event source to trigger your function.

请记住,Azure 门户编辑器需要直接访问你的正在运行的函数。Keep in mind that the Azure portal editor requires direct access to your running function. 通过 Azure 门户所做的任何代码更改都将要求你使用的设备浏览门户来将其 IP 列入允许列表。Any code changes through the Azure portal will require the device you're using to browse the portal to have its IP whitelisted. 但是,在实施了网络限制的情况下,你仍然可以使用“平台功能”选项卡下的任何内容。But you can still use anything under the platform features tab with network restrictions in place.

如何将我的函数应用限制到某个虚拟网络?How do I restrict my function app to a virtual network?

可以使用服务终结点将函数应用的入站流量限制倒某个虚拟网络。You are able to restrict inbound traffic for a function app to a virtual network using Service Endpoints. 此配置仍然允许函数应用对 Internet 进行出站调用。This configuration still allows the function app to make outbound calls to the internet.

若要完全限制某个函数以便所有流量流过虚拟网络,唯一方式是使用内部负载平衡应用服务环境。The only way to totally restrict a function such that all traffic flows through a virtual network is to use an internally load-balanced App Service Environment. 此选项将站点部署在虚拟网络中的专用基础结构上,并通过虚拟网络发送所有触发器和流量。This option deploys your site on a dedicated infrastructure inside a virtual network and sends all triggers and traffic through the virtual network.

有关如何使用应用服务环境的详细信息,请从在应用服务环境中创建和使用内部负载均衡器一文着手。For details on using an App Service Environment, start with the article Create and use an internal load balancer with an App Service Environment.

如何从函数应用访问虚拟网络中的资源?How can I access resources in a virtual network from a function app?

你可以使用虚拟网络集成从正在运行的函数访问虚拟网络中的资源。You can access resources in a virtual network from a running function by using virtual network integration. 有关详细信息,请参阅虚拟网络集成For more information, see Virtual network integration.

如何访问由服务终结点保护的资源?How do I access resources protected by service endpoints?

使用虚拟网络集成,可以从正在运行的函数访问由服务终结点保护的资源。By using virtual network integration you can access service-endpoint-secured resources from a running function. 有关详细信息,请参阅虚拟网络集成For more information, see virtual network integration.

如何从虚拟网络中的资源触发函数?How can I trigger a function from a resource in a virtual network?

可以使用服务终结点允许从虚拟网络调用 HTTP 触发器。You are able to allow HTTP triggers to be called from a virtual network using Service Endpoints.

还可以通过将函数应用部署到应用服务计划或应用服务环境,从虚拟网络中的所有其他资源触发函数。You can also trigger a function from all other resources in a virtual network by deploying your function app to an App Service plan, or App Service Environment. 有关详细信息,请参阅非 HTTP 虚拟网络触发器See non-HTTP virtual network triggers for more information

如何在虚拟网络中部署函数应用?How can I deploy my function app in a virtual network?

部署到应用服务环境是创建完全位于虚拟网络内部的函数应用的唯一方法。Deploying to an App Service Environment is the only way to create a function app that's wholly inside a virtual network. 若要详细了解如何将内部负载均衡器与应用服务环境配合使用,请从在应用服务环境中创建和使用内部负载均衡器一文着手。For details on using an internal load balancer with an App Service Environment, start with the article Create and use an internal load balancer with an App Service Environment.

对于只需单向访问虚拟网络资源或不太广泛的网络隔离的情况,请参阅功能网络概述For scenarios where you need only one-way access to virtual network resources, or less comprehensive network isolation, see the Functions networking overview.

后续步骤Next steps

若要详细了解网络和函数,请执行以下操作:To learn more about networking and functions: