Azure 应用程序网关 DNS 向后端池返回 307

Azure Application Gateway DNS returning 307 to backend pool

我正在尝试使用基本规则配置 Azure 应用程序网关。对于我的前端 IP,我创建了 set DNS name to whatever.canadacentral.cloudapp.azure.com 并上传了一个自签名证书。当我点击 https:// 时,一切正常,但是当我转到 https://whatever.canadacentral.cloudapp.azure.com it returns 307 redirecting me to my backend pool https://whatever.azurewebsites.net/

这是否与 canadacentral.cloudapp.azure.com 有关,我需要提供自定义 DNS?

这是我的应用程序网关模板:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "applicationGateways_ExampleDev_name": {
            "defaultValue": "ExampleDev",
            "type": "String"
        },
        "virtualNetworks_Ex_DEV_externalid": {
            "defaultValue": "/subscriptions/xxx/resourceGroups/Example-Ex-DEV/providers/Microsoft.Network/virtualNetworks/Ex-DEV",
            "type": "String"
        },
        "publicIPAddresses_ExampleDevIP_externalid": {
            "defaultValue": "/subscriptions/xxx/resourceGroups/Example-Ex-DEV/providers/Microsoft.Network/publicIPAddresses/ExampleDevIP",
            "type": "String"
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Network/applicationGateways",
            "apiVersion": "2019-09-01",
            "name": "[parameters('applicationGateways_ExampleDev_name')]",
            "location": "canadacentral",
            "properties": {
                "sku": {
                    "name": "WAF_v2",
                    "tier": "WAF_v2"
                },
                "gatewayIPConfigurations": [
                    {
                        "name": "appGatewayIpConfig",
                        "properties": {
                            "subnet": {
                                "id": "[concat(parameters('virtualNetworks_Ex_DEV_externalid'), '/subnets/default')]"
                            }
                        }
                    }
                ],
                "sslCertificates": [
                    {
                        "name": "ApplicationGateway",
                        "properties": {}
                    }
                ],
                "trustedRootCertificates": [],
                "frontendIPConfigurations": [
                    {
                        "name": "appGwPublicFrontendIp",
                        "properties": {
                            "privateIPAllocationMethod": "Dynamic",
                            "publicIPAddress": {
                                "id": "[parameters('publicIPAddresses_ExampleDevIP_externalid')]"
                            }
                        }
                    }
                ],
                "frontendPorts": [
                    {
                        "name": "port_80",
                        "properties": {
                            "port": 80
                        }
                    },
                    {
                        "name": "port_443",
                        "properties": {
                            "port": 443
                        }
                    }
                ],
                "backendAddressPools": [
                    {
                        "name": "ExampleApiDev",
                        "properties": {
                            "backendAddresses": [
                                {
                                    "fqdn": "Exampleapi-dev.azurewebsites.net"
                                }
                            ]
                        }
                    },
                    {
                        "name": "ExampleAuthDev",
                        "properties": {
                            "backendAddresses": [
                                {
                                    "fqdn": "Exampleauth-dev.azurewebsites.net"
                                }
                            ]
                        }
                    },
                    {
                        "name": "ExampleAppDev",
                        "properties": {
                            "backendAddresses": [
                                {
                                    "fqdn": "Exampleapp-dev.azurewebsites.net"
                                }
                            ]
                        }
                    }
                ],
                "backendHttpSettingsCollection": [
                    {
                        "name": "default",
                        "properties": {
                            "port": 80,
                            "protocol": "Http",
                            "cookieBasedAffinity": "Disabled",
                            "pickHostNameFromBackendAddress": true,
                            "affinityCookieName": "ApplicationGatewayAffinity",
                            "requestTimeout": 20,
                            "probe": {
                                "id": "[concat(resourceId('Microsoft.Network/applicationGateways', parameters('applicationGateways_ExampleDev_name')), '/probes/defaultxxx')]"
                            }
                        }
                    }
                ],
                "httpListeners": [
                    {
                        "name": "public-https",
                        "properties": {
                            "frontendIPConfiguration": {
                                "id": "[concat(resourceId('Microsoft.Network/applicationGateways', parameters('applicationGateways_ExampleDev_name')), '/frontendIPConfigurations/appGwPublicFrontendIp')]"
                            },
                            "frontendPort": {
                                "id": "[concat(resourceId('Microsoft.Network/applicationGateways', parameters('applicationGateways_ExampleDev_name')), '/frontendPorts/port_443')]"
                            },
                            "protocol": "Https",
                            "sslCertificate": {
                                "id": "[concat(resourceId('Microsoft.Network/applicationGateways', parameters('applicationGateways_ExampleDev_name')), '/sslCertificates/ApplicationGateway')]"
                            },
                            "hostNames": [],
                            "requireServerNameIndication": false
                        }
                    }
                ],
                "urlPathMaps": [],
                "requestRoutingRules": [
                    {
                        "name": "basic",
                        "properties": {
                            "ruleType": "Basic",
                            "httpListener": {
                                "id": "[concat(resourceId('Microsoft.Network/applicationGateways', parameters('applicationGateways_ExampleDev_name')), '/httpListeners/public-https')]"
                            },
                            "backendAddressPool": {
                                "id": "[concat(resourceId('Microsoft.Network/applicationGateways', parameters('applicationGateways_ExampleDev_name')), '/backendAddressPools/ExampleApiDev')]"
                            },
                            "backendHttpSettings": {
                                "id": "[concat(resourceId('Microsoft.Network/applicationGateways', parameters('applicationGateways_ExampleDev_name')), '/backendHttpSettingsCollection/default')]"
                            }
                        }
                    }
                ],
                "probes": [
                    {
                        "name": "default07a3e3ac-3c07-40f6-ad80-837f4cdd1009",
                        "properties": {
                            "protocol": "Http",
                            "path": "/swagger/index.html",
                            "interval": 30,
                            "timeout": 30,
                            "unhealthyThreshold": 3,
                            "pickHostNameFromBackendHttpSettings": true,
                            "minServers": 0,
                            "match": {
                                "statusCodes": [
                                    "200-399"
                                ]
                            }
                        }
                    }
                ],
                "rewriteRuleSets": [],
                "redirectConfigurations": [],
                "webApplicationFirewallConfiguration": {
                    "enabled": true,
                    "firewallMode": "Prevention",
                    "ruleSetType": "OWASP",
                    "ruleSetVersion": "3.0",
                    "disabledRuleGroups": [],
                    "exclusions": [],
                    "requestBodyCheck": true,
                    "maxRequestBodySizeInKb": 128,
                    "fileUploadLimitInMb": 50
                },
                "enableHttp2": false,
                "autoscaleConfiguration": {
                    "minCapacity": 0,
                    "maxCapacity": 2
                }
            }
        }
    ]
}

在这种情况下,对于应用程序网关 V2,您有来自 this document 的两个解决方案。

  1. Rewrite the location header

Set the host name in the location header to the application gateway's domain name. To do this, create a rewrite rule with a condition that evaluates if the location header in the response contains azurewebsites.net. It must also perform an action to rewrite the location header to have the application gateway's host name.

  1. Use a custom domain name

这样,您必须拥有一个自定义域,并在应用服务中添加自定义域,参见Map an existing custom DNS name to Azure App Service。你可以遵循这个过程: