你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

使用专用链接将 Azure Front Door Premium 连接到 Azure 应用程序网关

适用于: ✔️ Front Door Premium

本文会指导你完成配置 Azure Front Door Premium 以使用 Azure 专用链接私密连接到 Azure 应用程序网关的步骤。

先决条件

  • 一个包含源组的 Azure Front Door Premium 配置文件。 有关详细信息,请参阅 创建 Azure Front Door

  • Azure 应用程序网关。 有关如何创建应用程序网关的详细信息,请参阅 使用 Azure CLI 通过 Azure 应用程序网关引导 Web 流量

  • Azure Cloud Shell 或 Azure CLI。

    本文中的步骤在 Azure Cloud Shell 中以交互方式运行 Azure CLI 命令。 要在 Cloud Shell 中运行命令,请选择代码块右上角的“打开 Cloud Shell”。 选择“复制”以复制代码,并将其粘贴到 Cloud Shell 以运行。 也可以从 Azure 门户中运行 Cloud Shell。

    还可以 在本地安装 Azure CLI 以运行命令。 如果在本地运行 Azure CLI,请使用 az login 命令登录到 Azure。

启用与 Azure 应用程序网关的专用连接

  1. 按照配置 Azure 应用程序网关专用链接中的说明操作,但请勿完成创建专用终结点的最后一步。

  2. 转到应用程序网关的 “概述 ”选项卡,记下资源组名称、应用程序网关名称和订阅 ID。

  3. “设置”下,选择 “专用链接”。 记下专用链接服务的名称,该名称显示在“专用链接配置”选项卡中的“名称”列下

  4. 使用前面步骤中的值构造专用链接服务的资源 ID。 格式为 subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/Microsoft.Network/privateLinkServices/_e41f87a2_{applicationGatewayName}_{privateLinkResource.Name}。 配置 Front Door 源时使用此资源 ID。

创建源组,并将应用程序网关添加为源

  1. 在 Azure Front Door Premium 配置文件中,转到“设置”并选择“源组”

  2. 选择“添加

  3. 输入源组的名称

  4. 选择“+ 添加源”

  5. 使用下表配置源的设置:

    设置
    名称 输入名称以标识此源。
    原点类型 习惯
    主机名 请输入您的应用程序网关侦听器的主机名
    源主机标头 请输入您的应用程序网关侦听器的主机名
    HTTP 端口 80(默认值)
    HTTPS 端口 443(默认值)
    优先级 为源分配不同的优先级,以用于主要、次要和备份目的。
    重量 1000(默认值)。 使用权重在不同源之间分配流量。
    专用链接 启用专用链接服务
    选择专用链接 按 ID 或别名
    ID/别名 输入配置应用程序网关时获取的专用链接服务资源 ID。
    区域 选择与你的来源匹配或最接近的区域。
    请求消息 输入将在批准专用终结点时显示的自定义消息。

    屏幕截图显示将应用程序网关配置为专用源的源设置。

  6. 选择“添加”以保存源设置

  7. 选择“添加”以保存源组设置

批准专用终结点

  1. 导航到你在上一部分中使用专用链接配置的应用程序网关。 在“设置”下选择“专用链接”

  2. 选择“专用终结点连接”选项卡

  3. 找到 Azure Front Door Premium 中挂起的专用终结点请求,然后选择“批准”

  4. 批准后,连接状态将更新。 可能需要几分钟时间才能完全建立连接。 建立后,即可通过 Front Door 访问应用程序网关。 启用专用终结点后,将禁用从公共 Internet 直接访问应用程序网关的功能。 应用程序网关门户中专用终结点连接选项卡的屏幕截图。

启用与 Azure 应用程序网关的专用连接

按照配置 Azure 应用程序网关专用链接中的说明操作,但请勿完成创建专用终结点的最后一步。

创建源组,并将应用程序网关添加为源

  1. 使用 New-AzFrontDoorCdnOriginGroupHealthProbeSettingObject 创建用于存储运行状况探测设置的内存中对象。

    $healthProbeSetting = New-AzFrontDoorCdnOriginGroupHealthProbeSettingObject `
        -ProbeIntervalInSecond 60 `
        -ProbePath "/" `
        -ProbeRequestType GET `
        -ProbeProtocol Http
    
  2. 使用 New-AzFrontDoorCdnOriginGroupLoadBalancingSettingObject 创建用于存储负载均衡设置的内存中对象。

    $loadBalancingSetting = New-AzFrontDoorCdnOriginGroupLoadBalancingSettingObject `
        -AdditionalLatencyInMillisecond 50 `
        -SampleSize 4 `
        -SuccessfulSamplesRequired 3
    
  3. 运行 New-AzFrontDoorCdnOriginGroup,以创建包含应用程序网关的源组。

    $origingroup = New-AzFrontDoorCdnOriginGroup `
        -OriginGroupName myOriginGroup `
        -ProfileName myFrontDoorProfile `
        -ResourceGroupName myResourceGroup `
        -HealthProbeSetting $healthProbeSetting `
        -LoadBalancingSetting $loadBalancingSetting
    
  4. 使用 Get-AzApplicationGatewayFrontendIPConfig 命令获取应用程序网关的前端 IP 配置名称。

    $AppGw = Get-AzApplicationGateway -Name myAppGateway -ResourceGroupName myResourceGroup
    $FrontEndIPs= Get-AzApplicationGatewayFrontendIPConfig  -ApplicationGateway $AppGw
    $FrontEndIPs.name
    
  5. 使用 New-AzFrontDoorCdnOrigin 命令将应用程序网关添加到源组。

    New-AzFrontDoorCdnOrigin ` 
        -OriginGroupName myOriginGroup ` 
        -OriginName myAppGatewayOrigin ` 
        -ProfileName myFrontDoorProfile ` 
        -ResourceGroupName myResourceGroup ` 
        -HostName www.contoso.com ` 
        -HttpPort 80 ` 
        -HttpsPort 443 ` 
        -OriginHostHeader www.contoso.com ` 
        -Priority 1 ` 
        -PrivateLinkId /subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/myResourceGroup/providers/Microsoft.Network/applicationGateways/myAppGateway ` 
        -SharedPrivateLinkResourceGroupId $FrontEndIPs.name ` 
        -SharedPrivateLinkResourcePrivateLinkLocation CentralUS ` 
        -SharedPrivateLinkResourceRequestMessage 'Azure Front Door private connectivity request' ` 
        -Weight 1000 `
    

    注意

    SharedPrivateLinkResourceGroupId 是 Azure 应用程序网关前端 IP 配置的名称。

批准专用终结点

  1. 运行 Get-AzPrivateEndpointConnection,以检索需要批准的专用终结点连接的连接名称。

    Get-AzPrivateEndpointConnection -ResourceGroupName myResourceGroup -ServiceName myAppGateway -PrivateLinkResourceType Microsoft.Network/applicationgateways
    
  2. 运行 Approve-AzPrivateEndpointConnection 以批准专用终结点连接详细信息。 使用上一步的输出中的“名称”值来批准连接。

    Get-AzPrivateEndpointConnection -Name aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb.bbbbbbbb-1111-2222-3333-cccccccccccc -ResourceGroupName myResourceGroup -ServiceName myAppGateway -PrivateLinkResourceType Microsoft.Network/applicationgateways
    

完成 Azure Front Door 设置

使用 New-AzFrontDoorCdnRoute 命令来创建将你的终结点映射到源组的路由。 此路由会将来自终结点的请求转发到源组。

# Create a route to map the endpoint to the origin group

$Route = New-AzFrontDoorCdnRoute `
    -EndpointName myFrontDoorEndpoint `
    -Name myRoute `
    -ProfileName myFrontDoorProfile `
    -ResourceGroupName myResourceGroup `
    -ForwardingProtocol MatchRequest `
    -HttpsRedirect Enabled `
    -LinkToDefaultDomain Enabled `
    -OriginGroupId $origingroup.Id `
    -SupportedProtocol Http,Https

完成最后一步后,Azure Front Door 配置文件现已完全正常运行。

启用与 Azure 应用程序网关的专用连接

按照配置 Azure 应用程序网关专用链接中的步骤操作,跳过创建专用终结点的最后一步。

创建源组,并将应用程序网关添加为源

  1. 运行 az afd origin-group create 以创建源组。

    az afd origin-group create \
        --resource-group myResourceGroup \
        --origin-group-name myOriginGroup \
        --profile-name myFrontDoorProfile \
        --probe-request-type GET \
        --probe-protocol Http \
        --probe-interval-in-seconds 60 \
        --probe-path / \
        --sample-size 4 \
        --successful-samples-required 3 \
        --additional-latency-in-milliseconds 50
    
  2. 运行 az network application-gateway frontend-ip list 以获取应用程序网关的前端 IP 配置名称。

    az network application-gateway frontend-ip list --gateway-name myAppGateway --resource-group myResourceGroup
    
  3. 运行 az afd origin create,将应用程序网关添加为源组。

    az afd origin create \
        --enabled-state Enabled \
        --resource-group myResourceGroup \
        --origin-group-name myOriginGroup \
        --origin-name myAppGatewayOrigin \
        --profile-name myFrontDoorProfile \
        --host-name www.contoso.com \
        --origin-host-header www.contoso.com \
        --http-port 80  \
        --https-port 443 \
        --priority 1 \
        --weight 500 \
        --enable-private-link true \
        --private-link-location centralus \
        --private-link-request-message 'Azure Front Door private connectivity request.' \
        --private-link-resource /subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/myRGAG/providers/Microsoft.Network/applicationGateways/myAppGateway \
        --private-link-sub-resource-type myAppGatewayFrontendIPName
    

    注意

    private-link-sub-resource-type 是 Azure 应用程序网关前端 IP 配置名称。

批准专用终结点连接

  1. 运行 az network private-endpoint-connection list,获取需要批准的专用终结点连接的 ID

    az network private-endpoint-connection list --name myAppGateway --resource-group myResourceGroup --type Microsoft.Network/applicationgateways
    
  2. 运行 az network private-endpoint-connection approve,以使用上一步中的 ID 批准专用终结点连接。

    az network private-endpoint-connection approve --id /subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/myResourceGroup/providers/Microsoft.Network/applicationGateways/myAppGateway/privateEndpointConnections/aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb.bbbbbbbb-1111-2222-3333-cccccccccccc
    

完成 Azure Front Door 设置

运行 az afd route create,以创建将端点映射到源组的路由。 此路由会将来自终结点的请求转发到源组。

az afd route create \
    --resource-group myResourceGroup \
    --profile-name myFrontDoorProfile \
    --endpoint-name myFrontDoorEndpoint \
    --forwarding-protocol MatchRequest \
    --route-name myRoute \
    --https-redirect Enabled \
    --origin-group myOriginGroup \
    --supported-protocols Http Https \
    --link-to-default-domain Enabled

完成最后一步后,Azure Front Door 配置文件现已完全正常运行。

要避免的常见错误

在配置启用了 Azure 专用链接的 Azure 应用程序网关源时,常见错误如下:

  1. 在 Azure 应用程序网关上配置 Azure 专用链接之前配置 Azure Front Door 源。

  2. 将源的源类型配置为“应用程序网关”而不是“自定义”。 选择源类型作为“应用程序网关”时,源主机名会自动填充应用程序网关的 IP 地址。 这可能会导致“CertificateNameValidation”错误。 可以通过禁用证书使用者名称验证在公共源中避免此问题。 但对于启用私有链接的来源,证书主题名称验证是必需的。

  3. 使用 Azure 专用链接将 Azure 应用程序网关源添加到包含公共源的现有源组。 Azure Front Door 不允许在同一源组中混合公共和专用源。

  1. 提供不正确的 Azure 应用程序网关前端 IP 配置名称作为 SharedPrivateLinkResourceGroupId 的值。
  1. 提供不正确的 Azure 应用程序网关前端 IP 配置名称作为 private-link-sub-resource-type 的值。

后续步骤