|
| 1 | +--- |
| 2 | +title: Configure Azure Front Door in front of Azure API Management |
| 3 | +description: Learn how to front your API Management instance with Azure Front Door Standard/Premium to provide global HTTPS load balancing, TLS offloading, dynamic request acceleration, and other capabilities. |
| 4 | +services: api-management |
| 5 | +author: dlepow |
| 6 | + |
| 7 | +ms.service: api-management |
| 8 | +ms.topic: how-to |
| 9 | +ms.date: 09/27/2022 |
| 10 | +ms.author: danlep |
| 11 | +--- |
| 12 | +# Configure Front Door Standard/Premium in front of Azure API Management |
| 13 | + |
| 14 | +Azure Front Door is a modern application delivery network platform providing a secure, scalable content delivery network (CDN), dynamic site acceleration, and global HTTP(s) load balancing for your global web applications. When used in front of API Management, Front Door can provide TLS offloading, end-to-end TLS, load balancing, response caching of GET requests, and a web application firewall, among other capabilities. For a full list of supported features, see [What is Azure Front Door?](../frontdoor/front-door-overview.md) |
| 15 | + |
| 16 | +This article shows how to: |
| 17 | + |
| 18 | +* Set up an Azure Front Door Standard/Premium profile in front of a publicly accessible Azure API Management instance: either non-networked, or injected in a virtual network in [external mode](api-management-using-with-vnet.md). |
| 19 | +* Restrict API Management to accept API traffic only from Azure Front Door. |
| 20 | + |
| 21 | +## Prerequisites |
| 22 | + |
| 23 | +* An API Management instance. |
| 24 | + * If you choose to use a network-injected instance, it must be deployed in an external VNet. (Virtual network injection is supported in the Developer and Premium service tiers.) |
| 25 | +* Import one or more APIs to your API Management instance to confirm routing through Front Door. |
| 26 | + |
| 27 | +## Configure Azure Front Door |
| 28 | + |
| 29 | +### Create profile |
| 30 | + |
| 31 | +For steps to create an Azure Front Door Standard/Premium profile, see [Quickstart: Create an Azure Front Door profile - Azure portal](../frontdoor/create-front-door-portal.md). For this article, you may choose a Front Door Standard profile. For a comparison of Front Door Standard and Front Door Premium, see [Tier comparison](../frontdoor/standard-premium/tier-comparison.md). |
| 32 | + |
| 33 | +Configure the following Front Door settings that are specific to using the gateway endpoint of your API Management instance as a Front Door origin. For an explanation of other settings, see the Front Door quickstart. |
| 34 | + |
| 35 | +|Setting |Value | |
| 36 | +|---------|---------| |
| 37 | +| **Origin type** | Select **API Management** | |
| 38 | +| **Origin hostname** | Select the hostname of your API Management instance, for example, *myapim*.azure-api.net | |
| 39 | +| **Caching** | Select **Enable caching** for Front Door to [cache static content](../frontdoor/front-door-caching.md?pivots=front-door-standard-premium) | |
| 40 | +| **Query string caching behavior** | Select **Use Query String** | |
| 41 | + |
| 42 | +:::image type="content" source="media/front-door-api-management/quick-create-front-door-profile.png" alt-text="Screenshot of creating a Front Door profile in the portal."::: |
| 43 | + |
| 44 | +### Update default origin group |
| 45 | + |
| 46 | +After the profile is created, update the default origin group to include an API Management health probe. |
| 47 | + |
| 48 | +1. In the [portal](https://portal.azure.com), go to your Front Door profile. |
| 49 | +1. In the left menu, under **Settings** select **Origin groups** > **default-origin-group**. |
| 50 | +1. In the **Update origin group** window, configure the following **Health probe** settings and select **Update**: |
| 51 | + |
| 52 | + |
| 53 | + |Setting |Value | |
| 54 | + |---------|---------| |
| 55 | + |**Status** | Select **Enable health probes** | |
| 56 | + |**Path** | Enter `/status-0123456789abcdef` | |
| 57 | + |**Protocol** | Select **HTTPS** | |
| 58 | + |**Method** | Select **GET** | |
| 59 | + |**Interval (in seconds)** | Enter **30** | |
| 60 | + |
| 61 | + :::image type="content" source="media/front-door-api-management/update-origin-group.png" alt-text="Screenshot of updating the default origin group in the portal."::: |
| 62 | + |
| 63 | +### Update default route |
| 64 | + |
| 65 | +We recommend updating the default route that's associated with the API Management origin group to use HTTPS as the forwarding protocol. |
| 66 | + |
| 67 | +1. In the [portal](https://portal.azure.com), go to your Front Door profile. |
| 68 | +1. In the left menu, under **Settings** select **Origin groups**. |
| 69 | +1. Expand **default-origin-group**. |
| 70 | +1. In the context menu (**...**) of **default-route**, select **Configure route**. |
| 71 | +1. Set **Accepted protocols** to **HTTP and HTTPS**. |
| 72 | +1. Enable **Redirect all traffic to use HTTPS**. |
| 73 | +1. Set **Forwarding protocol** to **HTTPS only** and then select **Update**. |
| 74 | + |
| 75 | +### Test the configuration |
| 76 | + |
| 77 | +Test the Front Door profile configuration by calling an API hosted by API Management. First, call the API directly through the API Management gateway to ensure that the API is reachable. Then, call the API through Front Door. To test, you can use a command line client such as `curl` for the calls, or a tool such as [Postman](https://www.getpostman.com). |
| 78 | + |
| 79 | +### Call an API directly through API Management |
| 80 | + |
| 81 | +In the following example, an operation in the Demo Conference API hosted by the API Management instance is called directly using Postman. In this example, the instance's hostname is in the default `azure-api.net` domain, and a valid subscription key is passed using a request header. A successful response shows `200 OK` and returns the expected data: |
| 82 | + |
| 83 | +:::image type="content" source="media/front-door-api-management/test-api-management-gateway.png" alt-text="Screenshot showing calling API Management endpoint directly using Postman."::: |
| 84 | + |
| 85 | +### Call an API directly through Front Door |
| 86 | + |
| 87 | +In the following example, the same operation in the Demo Conference API is called using the Front Door endpoint configured for your instance. The endpoint's hostname in the `azurefd.net` domain is shown in the portal on the **Overview** page of your Front Door profile. A successful response shows `200 OK` and returns the same data as in the previous example: |
| 88 | + |
| 89 | +:::image type="content" source="media/front-door-api-management/test-front-door-gateway.png" alt-text="Screenshot showing calling Front Door endpoint using Postman."::: |
| 90 | + |
| 91 | +## Restrict incoming traffic to API Management instance |
| 92 | + |
| 93 | +Use API Management policies to ensure that your API Management instance accepts traffic only from Azure Front Door. You can accomplish this restriction using one or both of the [following methods](../frontdoor/front-door-faq.yml#how-do-i-lock-down-the-access-to-my-backend-to-only-azure-front-door-): |
| 94 | + |
| 95 | +1. Restrict incoming IP addresses to your API Management instances |
| 96 | +1. Restrict traffic based on the value of the `X-Azure-FDID` header |
| 97 | + |
| 98 | +### Restrict incoming IP addresses |
| 99 | + |
| 100 | +You can configure an inbound [ip-filter](/api-management-access-restriction-policies.md#CheckHTTPHeader) policy in API Management to allow only Front Door-related traffic, which includes: |
| 101 | + |
| 102 | +* **Front Door's backend IP address space** - Allow IP addresses corresponding to the *AzureFrontDoor.Backend* section in [Azure IP Ranges and Service Tags](https://www.microsoft.com/download/details.aspx?id=56519). |
| 103 | + |
| 104 | + > [!NOTE] |
| 105 | + > If your API Management instance is deployed in an external virtual network, accomplish the same restriction by adding an inbound network security group rule in the subnet used for your API Management instance. Configure the rule to allow HTTPS traffic from source service tag *AzureFrontDoor.Backend* on port 443. |
| 106 | +
|
| 107 | +* **Azure infrastructure services** - Allow IP addresses 168.63.129.16 and 169.254.169.254. |
| 108 | + |
| 109 | +### Check Front Door header |
| 110 | + |
| 111 | +Requests routed through Front Door include headers specific to your Front Door configuration. You can configure the [check-header](/api-management-access-restriction-policies.md#CheckHTTPHeader) policy to filter incoming requests based on the unique value of the `X-Azure-FDID` HTTP request header that is sent to API Management. This header value is the **Front Door ID**, which is shown in the portal on the **Overview** page of the Front Door profile. |
| 112 | + |
| 113 | +In the following policy example, the Front Door ID is specified using a [named value](api-management-howto-properties.md) named `FrontDoorId`. |
| 114 | + |
| 115 | +```xml |
| 116 | +<check-header name="X-Azure-FDID" failed-check-httpcode="403" failed-check-error-message="Invalid request." ignore-case="false"> |
| 117 | + <value>{{FrontDoorId}}</value> |
| 118 | +</check-header> |
| 119 | +``` |
| 120 | + |
| 121 | +Requests that aren't accompanied by a valid `X-Azure-FDID` header return a `403 Forbidden` response. |
| 122 | + |
| 123 | +## (Optional) Configure Front Door for developer portal |
| 124 | + |
| 125 | +Optionally, configure the API Management instance's developer portal as an endpoint in the Front Door profile. While the managed developer portal is already fronted by an Azure-managed CDN, you might want to take advantage of Front Door features such as a WAF. |
| 126 | + |
| 127 | +The following are high level steps to add an endpoint for the developer portal to your profile: |
| 128 | + |
| 129 | +* To add an endpoint and configure a route, see [Configure and endpoint with Front Door manager](../frontdoor/how-to-configure-endpoints.md). |
| 130 | + |
| 131 | +* When adding the route, add an origin group and origin settings to represent the developer portal: |
| 132 | + |
| 133 | + * **Origin type** - Select **Custom** |
| 134 | + * **Host name** - Enter the developer portal's hostname, for example, *myapim*.developer.azure-api.net |
| 135 | + |
| 136 | +For more information and details about settings, see [How to configure an origin for Azure Front Door](../frontdoor/how-to-configure-origin.md#create-a-new-origin-group). |
| 137 | + |
| 138 | +> [!NOTE] |
| 139 | +> If you've configured an [Azure AD](api-management-howto-aad.md) or [Azure AD B2C](api-management-howto-aad-b2c.md) identity provider for the developer portal, you need to update the corresponding app registration with an additional redirect URL to Front Door. In the app registration, add the URL for the developer portal endpoint configured in your Front Door profile. |
| 140 | +
|
| 141 | +## Next steps |
| 142 | + |
| 143 | +* To automate deployments of Front Door with API Management, see the template [Front Door Standard/Premium with API Management origin](https://azure.microsoft.com/resources/templates/front-door-standard-premium-api-management-external/) |
| 144 | + |
| 145 | +* Learn how to deploy [Web Application Firewall (WAF)](../web-application-firewall/afds/afds-overview.md) on Azure Front Door to protect the API Management instance from malicious attacks. |
0 commit comments