Azure应用网关DNS返回307到后端池

时间:2019-11-05 20:36:37

标签: azure azure-application-gateway

我正在尝试使用基本规则配置Azure应用程序网关。对于我的前端IP,我已经将DNS名称设置为what.canadacentral.cloudapp.azure.com,并上传了自签名证书。当我点击https://时,一切正常,但是当我转到https://whatever.canadacentral.cloudapp.azure.com时,它会返回307,将我重定向到我的后端池https://whatever.azurewebsites.net/

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

这是我的Application Gateway模板:

{
    "$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
                }
            }
        }
    ]
}

1 个答案:

答案 0 :(得分:1)

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

  1. Rewrite the location header
  

在位置标头中将主机名设置为应用程序网关的   域名。为此,请创建一个条件为rewrite rule的   评估响应中的位置标头是否包含   azurewebsites.net。它还必须执行一个操作来重写   位置标头以包含应用程序网关的主机名。

  1. Use a custom domain name

通过这种方式,您必须拥有自定义域并在应用服务中添加自定义域,请参见Map an existing custom DNS name to Azure App Service。您可以按照以下步骤进行: enter image description here