|
| 1 | +--- |
| 2 | +title: Use a custom domain with rule-based routing in Azure Container Apps (preview) |
| 3 | +description: Learn how to configure a custom domain with rule-based routing in Azure Container Apps. |
| 4 | +services: container-apps |
| 5 | +author: craigshoemaker |
| 6 | +ms.service: azure-container-apps |
| 7 | +ms.custom: devx-track-azurecli, devx-track-bicep |
| 8 | +ms.topic: how-to |
| 9 | +ms.date: 04/15/2025 |
| 10 | +ms.author: cshoe |
| 11 | +zone_pivot_groups: azure-cli-bicep |
| 12 | +--- |
| 13 | + |
| 14 | +# Use a custom domain with rule-based routing in Azure Container Apps (preview) |
| 15 | + |
| 16 | +HTTP route configurations support custom domains, allowing you to route traffic from your own domain names to your container apps. |
| 17 | + |
| 18 | +## Prerequisites |
| 19 | + |
| 20 | +- An existing Azure Container Apps environment |
| 21 | +- A custom domain that you own |
| 22 | +- SSL certificate for your domain (unless using automatic certificates) |
| 23 | +- Container apps deployed to your environment |
| 24 | + |
| 25 | +> [!NOTE] |
| 26 | +> To set up your own custom domain and certificate, see [Custom domain names and free managed certificates](./custom-domains-managed-certificates.md). |
| 27 | +> |
| 28 | +> If you set `bindingType: "Auto"`, you don't need a `certificateId`. Container Apps creates the certificate for you based on the domain. |
| 29 | +
|
| 30 | +## Configuration |
| 31 | + |
| 32 | +Update your Container Apps YAML file to include a `customDomains` section. The following example demonstrates how to set up this configuration. |
| 33 | + |
| 34 | +```yml |
| 35 | +customDomains: |
| 36 | + - name: "<CUSTOM_DOMAIN_ENDPOINT>" |
| 37 | + certificateId: "<CERTIFICATE_ID>" |
| 38 | + bindingType: "SniEnabled" # Can also be "Disabled", "Auto" |
| 39 | +rules: |
| 40 | + - description: "Routing to App1" |
| 41 | + routes: |
| 42 | + - match: |
| 43 | + prefix: "/1" |
| 44 | + action: |
| 45 | + prefixRewrite: "/" |
| 46 | + targets: |
| 47 | + - containerApp: "<CONTAINER_APP_NAME>" |
| 48 | + - description: "Routing to App2" |
| 49 | + routes: |
| 50 | + - match: |
| 51 | + prefix: "/2" |
| 52 | + action: |
| 53 | + prefixRewrite: "/" |
| 54 | + targets: |
| 55 | + - containerApp: "<CONTAINER_APP_NAME>" |
| 56 | +``` |
| 57 | +
|
| 58 | +This YAML configuration defines two routing rules for HTTP traffic. |
| 59 | +
|
| 60 | +| Property | Description | |
| 61 | +|---|---| |
| 62 | +| `customDomains.name` | The domain name you want to use (example: "app.contoso.com") | |
| 63 | +| `customDomains.certificateId` | Resource ID of your certificate (not needed with `bindingType: "Auto"`) | |
| 64 | +| `customDomains.bindingType` | How SSL is handled: "SniEnabled" (Server Name Indication), "Disabled" (HTTP only), or "Auto" (automatic certificate) | |
| 65 | +| `description` | Human-readable label for the rule | |
| 66 | +| `routes.match.prefix` | URL path prefix to match (example: "/api") | |
| 67 | +| `routes.action.prefixRewrite` | What to replace the matched prefix with before forwarding | |
| 68 | +| `targets.containerApp` | The name of the container app to route matching requests to | |
| 69 | + |
| 70 | +These rules allow different paths on your custom domain to route to different container apps while also modifying the request path before it reaches the destination app. |
| 71 | + |
| 72 | +## Work with your custom domain |
| 73 | + |
| 74 | +Use the following commands to configure and use your custom domain mapping. |
| 75 | + |
| 76 | +Before running the following commands, make sure to replace placeholders surrounded by `<>` with your own values. |
| 77 | + |
| 78 | +### List route configurations |
| 79 | + |
| 80 | +Use `az containerapp env http-route-config list` to list all the defined route configurations. |
| 81 | + |
| 82 | +```azurecli |
| 83 | +az containerapp env http-route-config list \ |
| 84 | + --resource-group <RESOURCE_GROUP_NAME> \ |
| 85 | + --name <ENVIRONMENT_NAME> |
| 86 | +``` |
| 87 | + |
| 88 | +### Create a new route configuration |
| 89 | + |
| 90 | +Use `az containerapp env http-route-config create` to create a new route configuration. |
| 91 | + |
| 92 | +```azurecli |
| 93 | +az containerapp env http-route-config create \ |
| 94 | + --resource-group <RESOURCE_GROUP_NAME> \ |
| 95 | + --name <ENVIRONMENT_NAME> \ |
| 96 | + --http-route-config-name <CONFIGURATION_NAME> \ |
| 97 | + --yaml <CONTAINER_APPS_CONFIG_FILE> |
| 98 | +``` |
| 99 | + |
| 100 | +### Update a route configuration |
| 101 | + |
| 102 | +Use `az containerapp env http-route-config update` to update an existing route configuration. |
| 103 | + |
| 104 | +```azurecli |
| 105 | +az containerapp env http-route-config update \ |
| 106 | + --resource-group <RESOURCE_GROUP_NAME> \ |
| 107 | + --name <ENVIRONMENT_NAME> \ |
| 108 | + --http-route-config-name <CONFIGURATION_NAME> \ |
| 109 | + --yaml <CONTAINER_APPS_CONFIG_FILE> |
| 110 | +``` |
| 111 | + |
| 112 | +### Show a specific route configuration |
| 113 | + |
| 114 | +Use `az containerapp env http-route-config show` to view details of a route configuration. |
| 115 | + |
| 116 | +```azurecli |
| 117 | +az containerapp env http-route-config show \ |
| 118 | + --resource-group <RESOURCE_GROUP_NAME> \ |
| 119 | + --name <ENVIRONMENT_NAME> \ |
| 120 | + --http-route-config-name <CONFIGURATION_NAME> |
| 121 | +``` |
| 122 | + |
| 123 | +### Delete a route configuration |
| 124 | + |
| 125 | +Use `az containerapp env http-route-config delete` to remove a route configuration. |
| 126 | + |
| 127 | +```azurecli |
| 128 | +az containerapp env http-route-config delete \ |
| 129 | + --resource-group <RESOURCE_GROUP_NAME> \ |
| 130 | + --name <ENVIRONMENT_NAME> \ |
| 131 | + --http-route-config-name <CONFIGURATION_NAME> |
| 132 | +``` |
| 133 | + |
| 134 | +## Verify HTTP routing |
| 135 | + |
| 136 | +After configuring your custom domain with rule-based routing: |
| 137 | + |
| 138 | +1. Navigate to your custom domain in a browser. For example, `https://app.contoso.com/1`. |
| 139 | + |
| 140 | +1. Verify that the request is routed to the first container app. |
| 141 | + |
| 142 | +1. Change the path to `/2`. For example, `https://app.contoso.com/2`. |
| 143 | + |
| 144 | +1. Verify that the request is now routed to the second container app. |
| 145 | + |
| 146 | +## Related content |
| 147 | + |
| 148 | +- [Rule-based routing in Azure Container Apps](./rule-based-routing.md) |
| 149 | +- [Custom domain names and free managed certificates](./custom-domains-managed-certificates.md) |
| 150 | +- [Azure CLI reference for HTTP route configuration](/cli/azure/containerapp/env/http-route-config) |
| 151 | + |
| 152 | +> [!TIP] |
| 153 | +> Having issues? Let us know on GitHub by opening an issue in the [Azure Container Apps repo](https://github.com/microsoft/azure-container-apps). |
0 commit comments