Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Microsoft Azure Development Cookbook Second Edition

You're reading from   Microsoft Azure Development Cookbook Second Edition Over 70 advanced recipes for developing scalable services with the Microsoft Azure platform

Arrow left icon
Product type Paperback
Published in Sep 2014
Publisher
ISBN-13 9781782170327
Length 422 pages
Edition 1st Edition
Tools
Concepts
Arrow right icon
Toc

Table of Contents (10) Chapters Close

Preface 1. Developing Cloud Services for Microsoft Azure FREE CHAPTER 2. Deploying Quickly with Azure Websites 3. Getting Storage with Blobs in Azure 4. Going Relational with the Azure SQL Database 5. Going NoSQL with Azure Tables 6. Messaging and Queues with the Storage and Service Bus 7. Managing Azure Resources with the Azure Management Libraries 8. Going In-memory with Azure Cache Index

Providing a custom domain name for a Cloud Service

A Cloud Service can expose an input endpoint to the Internet. This endpoint has a load balanced Virtual IP (VIP) address, which, for the time being, could change at each deployment.

Each VIP has an associated domain of the [servicednsprefix].cloudapp.net form. The servicednsprefix name is specified when the Cloud Service is created, and it is not changeable following the creation. A Cloud Service might be reached over the Internet at servicednsprefix.cloudapp.net. All Cloud Services exist under the cloudapp.net domain.

The DNS system supports a CNAME record that maps one domain to another. This allows, for example, www.servicename.com to be mapped to servicednsprefix.cloudapp.net. The DNS system also supports an A record that maps a domain to a fixed IP address. Unfortunately, reliable use of an A record is not recommended with a Cloud Service, because the IP address can change if the Cloud Service is deleted and redeployed.

It is not possible to acquire a public key certificate for the cloudapp.net domain as Microsoft controls it. Consequently, a CNAME is needed to map a custom domain to a cloudapp.net domain when HTTPS is used. We will see how to do this in the Implementing HTTPS in a web role recipe. In this recipe, we'll learn how to use CNAME to map a custom domain to a Cloud Service domain.

Getting ready

To use this recipe we need to control a custom domain (for example, customdomain.com) and must have created a Cloud Service (for example, theservice.cloudapp.net).

How to do it...

We are going to see how to use CNAME to map a custom domain to a Cloud Service using the following steps:

  1. Go to the dashboard of your DNS provider.
  2. On the CNAME management page of your DNS provider, add a new CNAME that maps www.customdomain.com to theservice.cloudapp.net.
  3. If your DNS provider supports the domain-forwarding feature, forward customdomain.com to www.customdomain.com.
  4. Wait for some time as the propagation of the DNS is recorded all around the world.

How it works...

In step 1, we navigated to the dashboard of the DNS service. Each DNS service operates on its own, so the interface might vary a lot from one vendor to another. In step 2, we told the DNS to forward the DNS request to theservice.cloudapp.net if the DNS www.customdomain.com is requested. In turn, when the Azure DNS is being requested from a remote client with the theservice.cloudapp.net record, it returns the actual IP address of the load balancer of the Cloud Service.

Finally, in step 3, we configured (if possible) forwarding so that the customdomain.com root/naked name is forwarded automatically to www.customdomain.com.

A DNS change could take from a few minutes to a few days, depending on the service provider. Expect the average time to wait until the DNS comes online to be about few hours.

There's more...

Sometimes (we read it as always), it is necessary to test the development environment while calling the production URL into the browser. This is possible by locally mapping (on the development workstation) the domain name to the loopback IP address.

The equivalent of a CNAME mapping in the development environment is a hosts file entry that maps servicename.com to 127.0.0.1. The hosts file is located in the %SystemRoot%\system32\drivers\etc folder. For example, adding the following entry to the hosts file maps servicename.com to 127.0.0.1:

127.0.0.1  servicename.com

Note that we need to remember to remove this entry from the hosts file on the development machine after the application is deployed to the Microsoft Azure data center. Otherwise, we will not be able to access the real servicename.com domain from the development machine.

We can also map the remote Azure service with this technique as follows:

  1. Discover the current IP address of the service by pinging it:
    ping theservice.cloudapp.net
    
  2. Add a line into the hosts file that maps the IP just discovered to the domain name.
You have been reading a chapter from
Microsoft Azure Development Cookbook Second Edition
Published in: Sep 2014
Publisher:
ISBN-13: 9781782170327
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime