How to Connect Azure App Service to Azure VM via Private Endpoint (VNet Integration)


2 views

When integrating Azure App Service with Azure VMs (or other App Services) through private networking, we're fundamentally dealing with Azure's Virtual Network (VNet) architecture. The public IP approach creates security concerns and potential latency, while private IP communication requires proper VNet configuration.

Azure provides two primary methods for private connectivity:

  • Regional VNet Integration: Connects your App Service to a VNet in the same region
  • Gateway-required VNet Integration: Connects to VNets in other regions or different subscriptions

Here's how to implement Regional VNet Integration:


# Azure CLI commands for VNet integration
az webapp vnet-integration add \
  --name YourWebAppName \
  --resource-group YourResourceGroup \
  --vnet YourVNetName \
  --subnet YourSubnetName

# Verify the integration
az webapp vnet-integration list \
  --name YourWebAppName \
  --resource-group YourResourceGroup

After establishing VNet integration, connect to your VM using its private IP:


// Example connection string for SQL Server on Azure VM
"Server=tcp:10.0.0.4,1433;Initial Catalog=YourDB;
User ID=YourUser;Password=YourPassword;"

For private communication between App Services:

  1. Deploy both apps in the same App Service Environment (ASE)
  2. Configure Internal Load Balancer (ILB) for the ASE
  3. Use private DNS resolution
  • Always use Service Endpoints or Private Endpoints for PaaS services
  • Configure Network Security Groups (NSGs) to restrict traffic
  • Consider using Azure Private Link for hybrid scenarios
  • Monitor connections with Azure Network Watcher

Common issues and solutions:

Issue Solution
DNS resolution failure Configure custom DNS servers or use Azure Private DNS
Connection timeouts Verify NSG rules and route tables
Subnet capacity Ensure subnet has enough available IPs (minimum /28)

When deploying a web application on Azure App Service that needs to communicate with a database hosted on an Azure Virtual Machine, the optimal solution would be to use private network connectivity rather than exposing the database to public internet. While Azure VMs have both public and private IPs by default, App Service instances don't come with private IPs out of the box.

There are several architectural approaches to achieve private connectivity between Azure App Service and Azure VM:

1. Azure Virtual Network Integration

The most straightforward solution is to use Azure App Service's VNet integration feature. This allows your web app to connect to resources in your Azure Virtual Network (VNet) through private IP addresses.

# Example ARM template snippet for VNet integration
{
  "apiVersion": "2018-11-01",
  "name": "virtualNetwork",
  "type": "config",
  "properties": {
    "vnetResourceId": "[resourceId('Microsoft.Network/virtualNetworks', 'your-vnet-name')]",
    "isSwift": true
  }
}

2. App Service Environment (ASE)

For more advanced scenarios, consider deploying your App Service in an App Service Environment, which runs in your VNet and provides isolated, dedicated compute resources.

Here's how to implement VNet integration for private connectivity:

  1. Create a Virtual Network if you don't have one
  2. Configure your VM to reside in the VNet
  3. Enable VNet integration for your App Service

For your second requirement of having two App Services communicate privately:

  • Deploy both apps in the same App Service Environment (ASE)
  • Or configure both with VNet integration to the same VNet
  • Use internal load balancers or private endpoints if needed

Remember to:

  • Configure Network Security Groups (NSGs) properly
  • Set up appropriate service tags and application security groups
  • Consider using Private Link for additional security

Common issues include:

  • DNS resolution problems - configure custom DNS servers if needed
  • Route table misconfigurations
  • Insufficient NSG permissions

To ensure optimal performance:

  • Place resources in the same Azure region
  • Consider proximity placement groups for latency-sensitive apps
  • Monitor connection metrics using Azure Monitor