Azure App Service: Complete Web Application Hosting Guide

Tyler Maginnis | January 20, 2024

AzureApp ServiceWeb AppsDeploymentHosting

Need Professional Azure Services?

Get expert assistance with your azure services implementation and management. Tyler on Tech Louisville provides priority support for Louisville businesses.

Same-day service available for Louisville area

Azure App Service: Complete Web Application Hosting Guide

Azure App Service provides a fully managed platform for hosting web applications, APIs, and mobile backends. This guide covers everything from basic deployment to advanced configuration and optimization techniques for small businesses.

Understanding Azure App Service

Service Plans

  • Free: Development and testing
  • Shared: Low-cost shared infrastructure
  • Basic: Dedicated compute for small workloads
  • Standard: Production workloads with auto-scaling
  • Premium: High-performance and advanced features
  • Isolated: Dedicated environment for enterprise workloads

Application Types

  • Web Apps: Host web applications and APIs
  • API Apps: RESTful API hosting
  • Mobile Apps: Mobile backend services
  • Function Apps: Serverless compute

Creating and Deploying Web Apps

PowerShell Setup

# Install Azure PowerShell module
Install-Module -Name Az -Force

# Connect to Azure
Connect-AzAccount

# Create resource group
New-AzResourceGroup -Name "WebApp-RG" -Location "East US"

# Create App Service plan
$plan = New-AzAppServicePlan `
    -ResourceGroupName "WebApp-RG" `
    -Name "BusinessPlan" `
    -Location "East US" `
    -Tier "Standard" `
    -NumberofWorkers 1 `
    -WorkerSize "Small"

# Create web app
$webapp = New-AzWebApp `
    -ResourceGroupName "WebApp-RG" `
    -Name "businesswebapp001" `
    -Location "East US" `
    -AppServicePlan "BusinessPlan"

Azure CLI Deployment

# Login to Azure
az login

# Create resource group
az group create --name "WebApp-RG" --location "eastus"

# Create App Service plan
az appservice plan create \
    --name "BusinessPlan" \
    --resource-group "WebApp-RG" \
    --location "eastus" \
    --sku "S1" \
    --number-of-workers 1

# Create web app
az webapp create \
    --name "businesswebapp001" \
    --resource-group "WebApp-RG" \
    --plan "BusinessPlan" \
    --runtime "NODE|18-lts"

Deployment Methods

Git Deployment

# Configure Git deployment
az webapp deployment source config \
    --name "businesswebapp001" \
    --resource-group "WebApp-RG" \
    --repo-url "https://github.com/company/webapp" \
    --branch "main" \
    --manual-integration

# Deploy from local Git
git remote add azure https://businesswebapp001.scm.azurewebsites.net/businesswebapp001.git
git push azure main

ZIP Deployment

# Deploy ZIP file
Publish-AzWebApp `
    -ResourceGroupName "WebApp-RG" `
    -Name "businesswebapp001" `
    -ArchivePath "C:\WebApp\deployment.zip"

Docker Container Deployment

# Deploy Docker container
az webapp config container set \
    --name "businesswebapp001" \
    --resource-group "WebApp-RG" \
    --docker-custom-image-name "myregistry.azurecr.io/myapp:latest" \
    --docker-registry-server-url "https://myregistry.azurecr.io" \
    --docker-registry-server-user "myregistry" \
    --docker-registry-server-password "password"

Configuration and Settings

Application Settings

# Set application settings
Set-AzWebApp `
    -ResourceGroupName "WebApp-RG" `
    -Name "businesswebapp001" `
    -AppSettings @{
        "DATABASE_CONNECTION" = "Server=businesssqlserver001.database.windows.net;Database=BusinessDB;User Id=sqladmin;Password=SecurePassword123!;"
        "API_KEY" = "your-api-key"
        "ENVIRONMENT" = "production"
    }

# Set connection strings
Set-AzWebApp `
    -ResourceGroupName "WebApp-RG" `
    -Name "businesswebapp001" `
    -ConnectionStrings @{
        "DefaultConnection" = @{
            "Value" = "Server=businesssqlserver001.database.windows.net;Database=BusinessDB;User Id=sqladmin;Password=SecurePassword123!;"
            "Type" = "SqlServer"
        }
    }

Custom Domains and SSL

# Add custom domain
New-AzWebAppCustomDomainMapping `
    -ResourceGroupName "WebApp-RG" `
    -WebAppName "businesswebapp001" `
    -DomainName "www.company.com"

# Upload SSL certificate
$cert = New-AzWebAppSSLCertificate `
    -ResourceGroupName "WebApp-RG" `
    -WebAppName "businesswebapp001" `
    -Name "company-ssl" `
    -CertificateFilePath "C:\Certificates\company.pfx" `
    -Password "certificate-password"

# Bind SSL certificate
New-AzWebAppSSLBinding `
    -ResourceGroupName "WebApp-RG" `
    -WebAppName "businesswebapp001" `
    -Name "www.company.com" `
    -CertificateFilePath "C:\Certificates\company.pfx" `
    -SslState "SniEnabled"

Scaling and Performance

Auto-Scaling Configuration

# Create auto-scale profile
$profile = New-AzAutoscaleProfile `
    -DefaultCapacity 2 `
    -MaximumCapacity 10 `
    -MinimumCapacity 1 `
    -Name "WebApp-Profile" `
    -RecurrenceFrequency "Week" `
    -ScheduleDay @("Monday", "Tuesday", "Wednesday", "Thursday", "Friday") `
    -ScheduleHour 9 `
    -ScheduleMinute 0 `
    -ScheduleTimeZone "Eastern Standard Time"

# Create scale-out rule
$scaleOutRule = New-AzAutoscaleRule `
    -MetricName "CpuPercentage" `
    -MetricResourceId "/subscriptions/subscription-id/resourceGroups/WebApp-RG/providers/Microsoft.Web/serverfarms/BusinessPlan" `
    -Operator "GreaterThan" `
    -MetricStatistic "Average" `
    -Threshold 70 `
    -TimeGrain 00:01:00 `
    -TimeWindow 00:05:00 `
    -ScaleActionCooldown 00:05:00 `
    -ScaleActionDirection "Increase" `
    -ScaleActionValue 1

# Create scale-in rule
$scaleInRule = New-AzAutoscaleRule `
    -MetricName "CpuPercentage" `
    -MetricResourceId "/subscriptions/subscription-id/resourceGroups/WebApp-RG/providers/Microsoft.Web/serverfarms/BusinessPlan" `
    -Operator "LessThan" `
    -MetricStatistic "Average" `
    -Threshold 30 `
    -TimeGrain 00:01:00 `
    -TimeWindow 00:05:00 `
    -ScaleActionCooldown 00:05:00 `
    -ScaleActionDirection "Decrease" `
    -ScaleActionValue 1

# Apply auto-scale setting
Add-AzAutoscaleSetting `
    -Location "East US" `
    -Name "WebApp-AutoScale" `
    -ResourceGroupName "WebApp-RG" `
    -TargetResourceId "/subscriptions/subscription-id/resourceGroups/WebApp-RG/providers/Microsoft.Web/serverfarms/BusinessPlan" `
    -AutoscaleProfile $profile `
    -Rule $scaleOutRule, $scaleInRule

Performance Optimization

# Enable Always On
Set-AzWebApp `
    -ResourceGroupName "WebApp-RG" `
    -Name "businesswebapp001" `
    -AlwaysOn $true

# Configure compression
Set-AzWebApp `
    -ResourceGroupName "WebApp-RG" `
    -Name "businesswebapp001" `
    -Use32BitWorkerProcess $false `
    -WebSocketsEnabled $true `
    -HttpLoggingEnabled $true `
    -DetailedErrorLoggingEnabled $true `
    -RequestTracingEnabled $true

Security Configuration

Authentication and Authorization

# Enable Azure AD authentication
Set-AzWebAppAuthSettings `
    -ResourceGroupName "WebApp-RG" `
    -Name "businesswebapp001" `
    -Enabled $true `
    -UnauthenticatedClientAction "RedirectToLoginPage" `
    -DefaultProvider "AzureActiveDirectory" `
    -ClientId "azure-ad-app-id" `
    -Issuer "https://sts.windows.net/tenant-id/"

IP Restrictions

# Add IP restriction
$ipRestriction = @{
    "ipAddress" = "203.0.113.0/24"
    "action" = "Allow"
    "priority" = 100
    "name" = "OfficeNetwork"
}

Set-AzWebApp `
    -ResourceGroupName "WebApp-RG" `
    -Name "businesswebapp001" `
    -IpSecurityRestrictions $ipRestriction

Managed Identity

# Enable system-assigned managed identity
Set-AzWebApp `
    -ResourceGroupName "WebApp-RG" `
    -Name "businesswebapp001" `
    -AssignIdentity $true

# Grant permissions to Key Vault
$webapp = Get-AzWebApp -ResourceGroupName "WebApp-RG" -Name "businesswebapp001"
Set-AzKeyVaultAccessPolicy `
    -VaultName "BusinessKeyVault" `
    -ObjectId $webapp.Identity.PrincipalId `
    -PermissionsToSecrets get,list

Monitoring and Diagnostics

Application Insights Integration

# Create Application Insights
$insights = New-AzApplicationInsights `
    -ResourceGroupName "WebApp-RG" `
    -Name "businesswebapp001-insights" `
    -Location "East US" `
    -Kind "web"

# Connect to web app
Set-AzWebApp `
    -ResourceGroupName "WebApp-RG" `
    -Name "businesswebapp001" `
    -AppSettings @{
        "APPINSIGHTS_INSTRUMENTATIONKEY" = $insights.InstrumentationKey
        "APPLICATIONINSIGHTS_CONNECTION_STRING" = $insights.ConnectionString
    }

Logging Configuration

# Enable application logging
Set-AzWebAppSlot `
    -ResourceGroupName "WebApp-RG" `
    -Name "businesswebapp001" `
    -Slot "production" `
    -AppLogsFileSystemQuotaInMB 35 `
    -AppLogsFileSystemRetentionInDays 7 `
    -HttpLoggingEnabled $true `
    -HttpLogsFileSystemQuotaInMB 35 `
    -HttpLogsFileSystemRetentionInDays 7

Health Checks

# Configure health check
Set-AzWebApp `
    -ResourceGroupName "WebApp-RG" `
    -Name "businesswebapp001" `
    -HealthCheckPath "/health"

Deployment Slots

Creating Deployment Slots

# Create staging slot
New-AzWebAppSlot `
    -ResourceGroupName "WebApp-RG" `
    -Name "businesswebapp001" `
    -Slot "staging" `
    -AppServicePlan "BusinessPlan"

# Configure slot settings
Set-AzWebAppSlot `
    -ResourceGroupName "WebApp-RG" `
    -Name "businesswebapp001" `
    -Slot "staging" `
    -AppSettings @{
        "DATABASE_CONNECTION" = "Server=businesssqlserver001.database.windows.net;Database=BusinessDB-Staging;User Id=sqladmin;Password=SecurePassword123!;"
        "ENVIRONMENT" = "staging"
    }

Slot Swapping

# Swap slots
Switch-AzWebAppSlot `
    -ResourceGroupName "WebApp-RG" `
    -Name "businesswebapp001" `
    -SourceSlotName "staging" `
    -DestinationSlotName "production"

# Swap with preview
Start-AzWebAppSlotSwap `
    -ResourceGroupName "WebApp-RG" `
    -Name "businesswebapp001" `
    -SourceSlotName "staging" `
    -DestinationSlotName "production" `
    -PreserveVnet $true

Backup and Recovery

Automated Backups

# Configure backup
$storageAccount = Get-AzStorageAccount -ResourceGroupName "WebApp-RG" -Name "businessbackupstore"
$backupConfig = New-AzWebAppBackup `
    -ResourceGroupName "WebApp-RG" `
    -Name "businesswebapp001" `
    -StorageAccountUrl "https://businessbackupstore.blob.core.windows.net/backups" `
    -FrequencyInterval 1 `
    -FrequencyUnit "Day" `
    -RetentionPeriodInDays 30 `
    -StartTime (Get-Date).AddDays(1) `
    -Databases @{
        "BusinessDB" = "Server=businesssqlserver001.database.windows.net;Database=BusinessDB;User Id=sqladmin;Password=SecurePassword123!;"
    }

# Start backup
Start-AzWebAppBackup -BackupConfig $backupConfig

Restore from Backup

# List available backups
Get-AzWebAppBackupList -ResourceGroupName "WebApp-RG" -Name "businesswebapp001"

# Restore from backup
Restore-AzWebAppBackup `
    -ResourceGroupName "WebApp-RG" `
    -Name "businesswebapp001" `
    -StorageAccountUrl "https://businessbackupstore.blob.core.windows.net/backups/backup-file.zip" `
    -OverwriteBackup $true

Cost Management

Resource Optimization

# Scale down during off-hours
$scaleDownProfile = New-AzAutoscaleProfile `
    -DefaultCapacity 1 `
    -MaximumCapacity 1 `
    -MinimumCapacity 1 `
    -Name "OffHours-Profile" `
    -RecurrenceFrequency "Week" `
    -ScheduleDay @("Monday", "Tuesday", "Wednesday", "Thursday", "Friday") `
    -ScheduleHour 18 `
    -ScheduleMinute 0 `
    -ScheduleTimeZone "Eastern Standard Time"

# Stop web app during maintenance
Stop-AzWebApp -ResourceGroupName "WebApp-RG" -Name "businesswebapp001"
Start-AzWebApp -ResourceGroupName "WebApp-RG" -Name "businesswebapp001"

Usage Monitoring

# Get resource usage
Get-AzMetric `
    -ResourceId "/subscriptions/subscription-id/resourceGroups/WebApp-RG/providers/Microsoft.Web/sites/businesswebapp001" `
    -MetricName "CpuTime" `
    -TimeGrain 01:00:00 `
    -StartTime (Get-Date).AddDays(-7) `
    -EndTime (Get-Date)

Advanced Features

WebJobs

# Create WebJob
$webJob = @{
    "name" = "DataProcessingJob"
    "type" = "triggered"
    "runCommand" = "node process-data.js"
    "settings" = @{
        "schedule" = "0 0 2 * * *"
    }
}

# Deploy WebJob
Invoke-RestMethod `
    -Uri "https://businesswebapp001.scm.azurewebsites.net/api/triggeredwebjobs" `
    -Method Post `
    -Headers @{
        "Authorization" = "Basic " + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("username:password"))
    } `
    -Body ($webJob | ConvertTo-Json) `
    -ContentType "application/json"

Virtual Network Integration

# Create virtual network
$vnet = New-AzVirtualNetwork `
    -ResourceGroupName "WebApp-RG" `
    -Name "WebApp-VNet" `
    -AddressPrefix "10.0.0.0/16" `
    -Location "East US"

# Create subnet
$subnet = Add-AzVirtualNetworkSubnetConfig `
    -Name "WebApp-Subnet" `
    -VirtualNetwork $vnet `
    -AddressPrefix "10.0.1.0/24"

$vnet | Set-AzVirtualNetwork

# Enable VNet integration
Set-AzWebApp `
    -ResourceGroupName "WebApp-RG" `
    -Name "businesswebapp001" `
    -VnetName "WebApp-VNet" `
    -SubnetName "WebApp-Subnet"

Best Practices

Development

  • Use deployment slots for staging environments
  • Implement CI/CD pipelines for automated deployments
  • Use Application Insights for monitoring
  • Configure health checks for reliability

Security

  • Enable HTTPS and SSL certificates
  • Use managed identities for authentication
  • Implement IP restrictions for sensitive applications
  • Regular security updates and patches

Performance

  • Enable Always On for production apps
  • Configure auto-scaling based on metrics
  • Use CDN for static content
  • Optimize application code and database queries

Troubleshooting

Common Issues

# Check application logs
Get-AzWebAppSlotLog `
    -ResourceGroupName "WebApp-RG" `
    -Name "businesswebapp001" `
    -Slot "production"

# Restart application
Restart-AzWebApp -ResourceGroupName "WebApp-RG" -Name "businesswebapp001"

# Check deployment status
Get-AzWebAppDeployment -ResourceGroupName "WebApp-RG" -Name "businesswebapp001"

Performance Issues

# Check resource usage
Get-AzMetric `
    -ResourceId "/subscriptions/subscription-id/resourceGroups/WebApp-RG/providers/Microsoft.Web/sites/businesswebapp001" `
    -MetricName "MemoryWorkingSet" `
    -TimeGrain 00:05:00

Conclusion

Azure App Service provides a comprehensive platform for hosting web applications with built-in scalability, security, and monitoring features. Proper configuration and optimization ensure reliable, high-performance applications that can grow with your business needs.

For professional Azure App Service implementation and optimization services in Louisville, contact Tyler on Tech Louisville for expert assistance with your web application hosting requirements.