Custom Domains and Certificates¶
Azure Container Apps supports custom hostnames and TLS certificates so you can serve ASP.NET Core applications on your own domain instead of the default azurecontainerapps.io address.
Architecture¶
flowchart TD
U[Client] --> DNS[Public DNS zone]
DNS --> INGRESS[Container Apps ingress]
DNS --> TXT[TXT record: asuid.<host>]
TXT --> ACA[Container Apps domain validation]
ACA --> CERT[TLS certificate binding]
CERT --> APP[ASP.NET Core App] Prerequisites¶
- Existing Container App:
$APP_NAMEin$RG - Existing Container Apps environment:
$ENVIRONMENT_NAME - Public DNS zone you control for the target domain
- Azure CLI with the Container Apps extension
Step 1: Get the app and environment values¶
export ENV_STATIC_IP=$(az containerapp env show \
--name "$ENVIRONMENT_NAME" \
--resource-group "$RG" \
--query "properties.staticIp" \
--output tsv)
export APP_FQDN=$(az containerapp show \
--name "$APP_NAME" \
--resource-group "$RG" \
--query "properties.configuration.ingress.fqdn" \
--output tsv)
export CUSTOM_DOMAIN_VERIFICATION_ID=$(az containerapp show \
--name "$APP_NAME" \
--resource-group "$RG" \
--query "properties.customDomainVerificationId" \
--output tsv)
Step 2: Create DNS records¶
az network dns record-set cname set-record \
--resource-group "$DNS_RG" \
--zone-name "contoso.com" \
--record-set-name "www" \
--cname "$APP_FQDN"
az network dns record-set txt add-record \
--resource-group "$DNS_RG" \
--zone-name "contoso.com" \
--record-set-name "asuid.www" \
--value "$CUSTOM_DOMAIN_VERIFICATION_ID"
Step 3: Add the hostname to the Container App¶
az containerapp hostname add \
--name "$APP_NAME" \
--resource-group "$RG" \
--hostname "www.contoso.com"
Step 4: Bind a certificate¶
az containerapp hostname bind \
--name "$APP_NAME" \
--resource-group "$RG" \
--hostname "www.contoso.com" \
--environment "$ENVIRONMENT_NAME" \
--validation-method CNAME
Step 5: Configure ASP.NET Core for forwarded headers¶
Container Apps terminates TLS before traffic reaches ASP.NET Core. Honor forwarded headers so redirects, links, and scheme detection stay correct.
using Microsoft.AspNetCore.HttpOverrides;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto | ForwardedHeaders.XForwardedHost
});
app.MapGet("/debug/host", (HttpContext context) => Results.Ok(new
{
scheme = context.Request.Scheme,
host = context.Request.Host.Value,
forwardedProto = context.Request.Headers["X-Forwarded-Proto"].ToString()
}));
Verification¶
az containerapp hostname list \
--name "$APP_NAME" \
--resource-group "$RG" \
--output table
az containerapp env certificate list \
--name "$ENVIRONMENT_NAME" \
--resource-group "$RG" \
--output table
curl --verbose https://www.contoso.com/