Skip to content

Instantly share code, notes, and snippets.

@machv
Last active March 5, 2025 15:01
Show Gist options
  • Save machv/3dc0c1326bfffd20ce548f203fdba116 to your computer and use it in GitHub Desktop.
Save machv/3dc0c1326bfffd20ce548f203fdba116 to your computer and use it in GitHub Desktop.
Azure Web App with custom domain names and PHP content.

Deploy infra

az deployment group create --resource-group "rg-app" --template-file "main.bicep"

deploy App

Compress-Archive -Path ".\app\*" -DestinationPath "app.zip"
az webapp deploy --resource-group "rg-app" --name "wapp-vm-redirapp" --type zip --src-path ./app.zip
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Azure Redir App</title>
</head>
<body>
<h1>
<h1>Welcome to Azure Redir App</h1>
</h1>
<p>
Current time is <strong><?php echo date("Y-m-d H:i:s"); ?></strong>
</p>
<p>
Hostname is <strong><?php echo $_SERVER['HTTP_HOST']; ?></strong>
</p>
</body>
</html>
<?php
header("Location: http://new.tld", true, 307);
?>
param location string = resourceGroup().location
param webAppName string = 'vm-redirapp'
param sku string = 'B2'
param linuxFxVersion string = 'PHP|8.3'
@description('Domains that are validated in DNS but not deployed yet.')
param validatedDomains array = [
'test3.mach.im'
'test4.mach.im'
'test5.mach.im'
'test6.mach.im'
]
@description('Domains that are validated in DNS and have also a certificate in Azure deployed.')
param domainsWithCertificate array = [
'test3.mach.im'
'test4.mach.im'
'test5.mach.im'
]
var appServicePlanName = toLower('asp-${webAppName}')
var webSiteName = toLower('wapp-${webAppName}')
resource plan 'Microsoft.Web/serverfarms@2020-06-01' = {
name: appServicePlanName
location: location
properties: {
reserved: true
}
sku: {
name: sku
}
kind: 'linux'
}
resource site 'Microsoft.Web/sites@2024-04-01' = {
name: webSiteName
location: location
properties: {
serverFarmId: plan.id
siteConfig: {
linuxFxVersion: linuxFxVersion
}
}
}
output verificationRecord string = site.properties.customDomainVerificationId
output defaultHostName string = site.properties.defaultHostName
output inboundIp string = site.properties.inboundIpAddress
@description('These DNS records need to be added to zone before creating bindings.')
var customDns = flatten(map(validatedDomains, domain => [
'asuid.${domain} TXT ${site.properties.customDomainVerificationId}'
'${domain} CNAME ${site.properties.defaultHostName}'
]))
output customDnsRecords array = customDns
@batchSize(1)
resource binding 'Microsoft.Web/sites/hostNameBindings@2019-08-01' = [
for domain in validatedDomains: {
name: domain
parent: site
properties: {
siteName: site.name
hostNameType: 'Verified'
sslState: contains(domainsWithCertificate, domain) ? 'SniEnabled' : 'Disabled'
}
}
]
resource certificate 'Microsoft.Web/certificates@2021-01-15' = [
for domain in validatedDomains: {
name: '${webSiteName}-${domain}'
location: resourceGroup().location
properties: {
serverFarmId: plan.id
hostNames: [
domain
]
canonicalName: domain
}
dependsOn: [
binding
]
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment