|
| 1 | +--- |
| 2 | +title: Manage traffic to App Service |
| 3 | +titleSuffix: Azure Application Gateway |
| 4 | +description: This article provides guidance on how to configure Azure App service web apps as members in backend pool on an existing or new Application Gateway. |
| 5 | +services: application-gateway |
| 6 | +author: xstof |
| 7 | +ms.service: application-gateway |
| 8 | +ms.topic: how-to |
| 9 | +ms.date: 17/02/2022 |
| 10 | +ms.author: christoc |
| 11 | +--- |
| 12 | +<!-- https://docs.microsoft.com/en-us/azure/application-gateway/configure-web-app-portal --> |
| 13 | + |
| 14 | +# Configure App Service with Application Gateway |
| 15 | + |
| 16 | +Application gateway allows you to have an App Service app or other multi-tenant service as a back-end pool member. In this article, you learn to configure an App Service app with Application Gateway. The configuration for Application Gateway will differ depending on how App Service will be accessed. |
| 17 | + |
| 18 | +The first option is to have Application Gateway access App Service using it's default domain, suffixed as ".azurewebsites.net". This is the easiest configuration as it does not require a custom domain. As such it allows for a quick convenient setup. Note however that this configuration comes with limitations and that we recommend to review the implications of using different host names between the client and Application Gateway and between Application and App Service in the backend. For more information, please review the article in Architecture Center: [Preserve the original HTTP host name between a reverse proxy and its backend web application](/azure/architecture/best-practices/host-name-preservation) |
| 19 | + |
| 20 | +The second option makes use of a custom domain on both Application Gateway and the App Service in the backend. This the configuration which is commonly recommended for production-grade scenarios and meets the practice of not changing the host name in the request flow. It does require however you have a custom domain (and associated certificate) available so to avoid having to rely on the default ".azurewebsites" domain. |
| 21 | + |
| 22 | + |
| 23 | +<!-- see example: https://github.dev/MicrosoftDocs/azure-docs/blob/main/articles/app-service/quickstart-dotnetcore.md --> |
| 24 | +<!-- markdownlint-disable MD044 --> |
| 25 | +:::zone target="docs" pivot="app-service-domainconfig-defaultdomain" |
| 26 | +<!-- markdownlint-enable MD044 --> |
| 27 | + |
| 28 | +When App Service does not have a custom domain associated with it, the host header on the incoming request on the web application will need to be set to the default domain, suffixed with ".azurewebsites.net" or else the platform will not be able to properly route the request. |
| 29 | + |
| 30 | +This means that the host header in the original request received by the Application Gateway will be different from the host name of the backend App Service. |
| 31 | + |
| 32 | +:::zone-end |
| 33 | + |
| 34 | +:::zone target="docs" pivot="app-service-domainconfig-customdomain" |
| 35 | + |
| 36 | +By associating both Application Gateway and App Service in the backend pool to the same domain name, the request flow does not need to override host name and the backend web application will see the original host as was used by the client. |
| 37 | + |
| 38 | +:::zone-end |
| 39 | + |
| 40 | +In this article you'll learn how to: |
| 41 | +- Add App Service as backend pool to the Application Gateway |
| 42 | +- Configure the HTTP Settings for the connection to App Service |
| 43 | + |
| 44 | +## Prerequisites |
| 45 | + |
| 46 | +:::zone target="docs" pivot="app-service-domainconfig-defaultdomain" |
| 47 | + |
| 48 | +- Application gateway: Create an application gateway without a backend pool target. For more information, see [Quickstart: Direct web traffic with Azure Application Gateway - Azure portal](quick-create-portal.md) |
| 49 | + |
| 50 | +- App service: If you don't have an existing App service, see [App service documentation](../app-service/index.yml). |
| 51 | + |
| 52 | +:::zone-end |
| 53 | + |
| 54 | +:::zone target="docs" pivot="app-service-domainconfig-customdomain" |
| 55 | + |
| 56 | +- Application Gateway: Create an application gateway without a backend pool target. For more information, see [Quickstart: Direct web traffic with Azure Application Gateway - Azure portal](quick-create-portal.md) |
| 57 | + |
| 58 | +- App Service: If you don't have an existing App service, see [App service documentation](../app-service/index.yml). |
| 59 | + |
| 60 | +- A custom domain name and associated certificate, stored in Key Vault. For more information on how to store certificates in Key Vault, see [Tutorial: Import a certificate in Azure Key Vault](../key-vault/certificates/tutorial-import-certificate.md) |
| 61 | + |
| 62 | +:::zone-end |
| 63 | + |
| 64 | +## Add App service as backend pool |
| 65 | + |
| 66 | +### [Azure Portal](#tab/azp) |
| 67 | + |
| 68 | +1. In the Azure portal, select your application gateway. |
| 69 | + |
| 70 | +2. Under **Backend pools**, select the backend pool. |
| 71 | + |
| 72 | +3. Under **Target type**, select **App Services**. |
| 73 | + |
| 74 | +4. Under **Target** select your App Service. |
| 75 | + |
| 76 | + :::image type="content" source="./media/configure-web-app-portal/backend-pool.png" alt-text="App service backend"::: |
| 77 | + |
| 78 | + > [!NOTE] |
| 79 | + > The dropdown only populates those app services which are in the same subscription as your Application Gateway. If you want to use an app service which is in a different subscription than the one in which the Application Gateway is, then instead of choosing **App Services** in the **Targets** dropdown, choose **IP address or hostname** option and enter the hostname (example.azurewebsites.net) of the app service. |
| 80 | +
|
| 81 | +5. Select **Save**. |
| 82 | + |
| 83 | +:::zone target="docs" pivot="app-service-domainconfig-customdomain" |
| 84 | + |
| 85 | +TEST - custom text for custom domain |
| 86 | + |
| 87 | +:::zone-end |
| 88 | + |
| 89 | +:::zone target="docs" pivot="app-service-domainconfig-defaultdomain" |
| 90 | + |
| 91 | +TEST - custom text for default domain |
| 92 | + |
| 93 | +:::zone-end |
| 94 | + |
| 95 | +### [Powershell](#tab/powershell) |
| 96 | + |
| 97 | +TODO |
| 98 | + |
| 99 | + |
| 100 | +## Edit HTTP settings for App Service |
| 101 | + |
| 102 | +1. Under **HTTP Settings**, select the existing HTTP setting. |
| 103 | + |
| 104 | +2. Under **Override with new host name**, select **Yes**. |
| 105 | +3. Under **Host name override**, select **Pick host name from backend target**. |
| 106 | +4. Select **Save**. |
| 107 | + |
| 108 | + :::image type="content" source="./media/configure-web-app-portal/http-settings.png" alt-text="Pick host name from backend http settings"::: |
| 109 | + |
| 110 | +## Additional configuration in case of redirection to app service's relative path |
| 111 | + |
| 112 | +When the app service sends a redirection response to the client to redirect to its relative path (For example, a redirect from `contoso.azurewebsites.net/path1` to `contoso.azurewebsites.net/path2`), it uses the same hostname in the location header of its response as the one in the request it received from the application gateway. So the client will make the request directly to `contoso.azurewebsites.net/path2` instead of going through the application gateway (`contoso.com/path2`). Bypassing the application gateway isn't desirable. |
| 113 | + |
| 114 | +If in your use case, there are scenarios where the App service will need to send a redirection response to the client, perform the [additional steps to rewrite the location header](./troubleshoot-app-service-redirection-app-service-url.md#sample-configuration). |
| 115 | + |
| 116 | +## Restrict access |
| 117 | + |
| 118 | +The web apps deployed in these examples use public IP addresses that can be accessed directly from the Internet. This helps with troubleshooting when you are learning about a new feature and trying new things. But if you intend to deploy a feature into production, you'll want to add more restrictions. |
| 119 | + |
| 120 | +One way you can restrict access to your web apps is to use [Azure App Service static IP restrictions](../app-service/app-service-ip-restrictions.md). For example, you can restrict the web app so that it only receives traffic from the application gateway. Use the app service IP restriction feature to list the application gateway VIP as the only address with access. |
| 121 | + |
| 122 | +## Next steps |
| 123 | + |
| 124 | +To learn more about the App service and other multi-tenant support with application gateway, see [multi-tenant service support with application gateway](./application-gateway-web-app-overview.md). |
0 commit comments