While we can use Azure Traffic Manager to manage traffic to Azure Websites, we can also extend the Azure Traffic Manager functionality to manage traffic between Azure Websites and Azure Virtual Machines hosting the Websites.
I wrote this blog for the Failover scenario, however, you can use the same configuration for other routing options available for Azure Traffic Manager (Round Robin and Performance).
Step 1: Creating an Azure Website
I created a sample site in Visual Studio and deployed it as an Azure Website named: “MyTrafficManagerTest” in East US region
Step 2: Creating an Azure VM to host your Website
I selected the option to create a new Virtual Machine and deployed the same Website on the Virtual Machine:
Here are snapshots of my sample that I used for publishing my Website using Visual Studio:
NOTE: You will need to have “Enable IIS and Deployment” setting checked when we deploy the Website to an Azure Virtual Machine for the Web Deployment to work from Visual Studio. This setting is enabled by default when you publish a Website to a new Virtual Machine from Visual Studio. If you are deploying the site to an existing Azure Virtual Machine, then please install Web Deploybefore you attempt Website deployment from Visual Studio.
Here is a snapshot of the Connection Setting for publishing the Azure Website:
Step 3: Traffic Manager Configuration
We will now use Azure Traffic Manager to configure for the Azure Website and the Website Hosted on Azure VM.
Create a new Traffic Manager configuration from the Azure Portal by following these steps:
Let’s add the Endpoint for Azure Website:
Now, let’s select the VM instance (in this case, TestWestVM), this would be listed as a Cloud Service (extension : cloudapp.net):
We are done!!
Testing this configuration:
Now, let’s test the Failover:
I stopped Azure Website: MyTrafficManagerTest.azurewebsites.net
In Traffic Manager, I see that the Azure Websites endpoint is in the stopped state:
When I browse: http://websitesvm.azurewebites.net, I now see that the requests are now being handled by Azure VM : TestWestVM which is hosted in West US region.
We can use DigWebInterface to confirm the endpoint that is serving the request for your Traffic Manager.
When I disable the Azure Website endpoint, Traffic Manager requests are bound to the Azure VM :
We see that the Traffic Manager is resolving to the address of the Virtual Machine:
websitesvm.trafficmanager.net. 299 IN CNAME testwestvm.cloudapp.net.
Similarly, when I disable the Azure Virtual Machine Endpoint, I see that the requests are now being served by the Azure Website:
We see that the Traffic Manager is resolving to the Azure Website address:
websitesvm.trafficmanager.net. 299 IN CNAME mytrafficmanagertest.azurewebsites.net.