应用程序网关的多站点托管功能Application Gateway multiple site hosting

托管多个站点可以让你在同一应用程序网关实例上配置多个 Web 应用程序。Multiple site hosting enables you to configure more than one web application on the same application gateway instance. 此功能可以将多达 100 个网站添加到一个应用程序网关中,从而为部署配置更有效的拓扑。This feature allows you to configure a more efficient topology for your deployments by adding up to 100 websites to one application gateway. 每个网站都可以定向到自己的后端池。Each website can be directed to its own backend pool. 在以下示例中,应用程序网关通过两个名为 ContosoServerPool 和 FabrikamServerPool 的后端服务器池来为 contoso.com 和 fabrikam.com 提供流量。In the following example, application gateway is serving traffic for contoso.com and fabrikam.com from two back-end server pools called ContosoServerPool and FabrikamServerPool.

imageURLroute

Important

规则将按照门户中的列出顺序进行处理。Rules are processed in the order they are listed in the portal. 我们强烈建议先配置多站点侦听器,然后再配置基本侦听器。It is highly recommended to configure multi-site listeners first prior to configuring a basic listener. 这可以确保将流量路由到适当的后端。This will ensure that traffic gets routed to the right back end. 如果基本侦听器先列出并且与传入请求匹配,则该侦听器将处理该请求。If a basic listener is listed first and matches an incoming request, it gets processed by that listener.

http://contoso.com 的请求路由到 ContosoServerPool,对 http://fabrikam.com 的请求路由到 FabrikamServerPool。Requests for http://contoso.com are routed to ContosoServerPool, and http://fabrikam.com are routed to FabrikamServerPool.

同样可以将同一父域的两个子域托管到同一应用程序网关部署。Similarly two subdomains of the same parent domain can be hosted on the same application gateway deployment. 例如,在单个应用程序网关部署中托管的 http://blog.contoso.comhttp://app.contoso.com 都是使用子域。Examples of using subdomains could include http://blog.contoso.com and http://app.contoso.com hosted on a single application gateway deployment.

主机标头和服务器名称指示 (SNI)Host headers and Server Name Indication (SNI)

可以通过三种常用机制在同一基础结构上启用多站点托管功能。There are three common mechanisms for enabling multiple site hosting on the same infrastructure.

  1. 托管多个 Web 应用程序时,每个唯一的 IP 地址可以托管一个应用程序。Host multiple web applications each on a unique IP address.
  2. 使用主机名在同一 IP 地址上托管多个 Web 应用程序。Use host name to host multiple web applications on the same IP address.
  3. 使用不同的端口在同一 IP 地址上托管多个 Web 应用程序。Use different ports to host multiple web applications on the same IP address.

目前,应用程序网关通过单个公共 IP 地址来侦听流量。Currently an application gateway gets a single public IP address on which it listens for traffic. 因此,目前不支持使用多个自带 IP 地址的应用程序。Therefore supporting multiple applications, each with its own IP address, is currently not supported. 应用程序网关支持托管多个应用程序,每个应用程序在不同的端口上进行侦听,但此方案要求应用程序接受非标准端口上的流量,通常情况下这不是所需的配置。Application Gateway supports hosting multiple applications each listening on different ports but this scenario would require the applications to accept traffic on non-standard ports and is often not a desired configuration. 应用程序网关需要使用 HTTP 1.1 主机标头才能在相同的公共 IP 地址和端口上托管多个网站。Application Gateway relies on HTTP 1.1 host headers to host more than one website on the same public IP address and port. 在应用程序网关上托管的站点也可以通过服务器名称指示 (SNI) TLS 扩展来支持 SSL 卸载。The sites hosted on application gateway can also support SSL offload with Server Name Indication (SNI) TLS extension. 这种情况意味着,客户端浏览器和后端 Web 场必须支持 RFC 6066 中定义的 HTTP/1.1 和 TLS 扩展。This scenario means that the client browser and backend web farm must support HTTP/1.1 and TLS extension as defined in RFC 6066.

侦听器配置元素Listener configuration element

现有的 HTTPListener 配置元素得到了增强,因此可以支持主机名称和服务器名称指示元素,方便应用程序网关将流量路由到相应的后端池。Existing HTTPListener configuration element is enhanced to support host name and server name indication elements, which is used by application gateway to route traffic to appropriate backend pool. 以下代码示例是模板文件中 HttpListeners 元素的代码片段。The following code example is the snippet of HttpListeners element from template file.

"httpListeners": [
    {
        "name": "appGatewayHttpsListener1",
        "properties": {
            "FrontendIPConfiguration": {
                "Id": "/subscriptions/<subid>/resourceGroups/<rgName>/providers/Microsoft.Network/applicationGateways/applicationGateway1/frontendIPConfigurations/DefaultFrontendPublicIP"
            },
            "FrontendPort": {
                "Id": "/subscriptions/<subid>/resourceGroups/<rgName>/providers/Microsoft.Network/applicationGateways/applicationGateway1/frontendPorts/appGatewayFrontendPort443'"
            },
            "Protocol": "Https",
            "SslCertificate": {
                "Id": "/subscriptions/<subid>/resourceGroups/<rgName>/providers/Microsoft.Network/applicationGateways/applicationGateway1/sslCertificates/appGatewaySslCert1'"
            },
            "HostName": "contoso.com",
            "RequireServerNameIndication": "true"
        }
    },
    {
        "name": "appGatewayHttpListener2",
        "properties": {
            "FrontendIPConfiguration": {
                "Id": "/subscriptions/<subid>/resourceGroups/<rgName>/providers/Microsoft.Network/applicationGateways/applicationGateway1/frontendIPConfigurations/appGatewayFrontendIP'"
            },
            "FrontendPort": {
                "Id": "/subscriptions/<subid>/resourceGroups/<rgName>/providers/Microsoft.Network/applicationGateways/applicationGateway1/frontendPorts/appGatewayFrontendPort80'"
            },
            "Protocol": "Http",
            "HostName": "fabrikam.com",
            "RequireServerNameIndication": "false"
        }
    }
],

可以访问 Resource Manager template using multiple site hosting(使用多站点托管的 Resource Manager 模板),了解如何进行基于模板的端到端部署。You can visit Resource Manager template using multiple site hosting for an end to end template-based deployment.

路由规则Routing rule

不需更改路由规则。There is no change required in the routing rule. 应继续选择“基本”路由规则,以便将适当的站点侦听器绑定到相应的后端地址池。The routing rule 'Basic' should continue to be chosen to tie the appropriate site listener to the corresponding backend address pool.

"requestRoutingRules": [
{
    "name": "<ruleName1>",
    "properties": {
        "RuleType": "Basic",
        "httpListener": {
            "id": "/subscriptions/<subid>/resourceGroups/<rgName>/providers/Microsoft.Network/applicationGateways/applicationGateway1/httpListeners/appGatewayHttpsListener1')]"
        },
        "backendAddressPool": {
            "id": "/subscriptions/<subid>/resourceGroups/<rgName>/providers/Microsoft.Network/applicationGateways/applicationGateway1/backendAddressPools/ContosoServerPool')]"
        },
        "backendHttpSettings": {
            "id": "/subscriptions/<subid>/resourceGroups/<rgName>/providers/Microsoft.Network/applicationGateways/applicationGateway1/backendHttpSettingsCollection/appGatewayBackendHttpSettings')]"
        }
    }

},
{
    "name": "<ruleName2>",
    "properties": {
        "RuleType": "Basic",
        "httpListener": {
            "id": "/subscriptions/<subid>/resourceGroups/<rgName>/providers/Microsoft.Network/applicationGateways/applicationGateway1/httpListeners/appGatewayHttpListener2')]"
        },
        "backendAddressPool": {
            "id": "/subscriptions/<subid>/resourceGroups/<rgName>/providers/Microsoft.Network/applicationGateways/applicationGateway1/backendAddressPools/FabrikamServerPool')]"
        },
        "backendHttpSettings": {
            "id": "/subscriptions/<subid>/resourceGroups/<rgName>/providers/Microsoft.Network/applicationGateways/applicationGateway1/backendHttpSettingsCollection/appGatewayBackendHttpSettings')]"
        }
    }

}
]

后续步骤Next steps

了解多站点托管以后,请转到创建使用多站点托管的应用程序网关,以便创建能够支持多个 Web 应用程序的应用程序网关。After learning about multiple site hosting, go to create an application gateway using multiple site hosting to create an application gateway with ability to support more than one web application.