Add Custom Domain in Azure App Service

You don’t have to have custom domains to run your apps in Azure App Service but it is best practice to adopt easy to understand name and guarantee that domain (or subdomains) is not taken by others. If you have a custom domain, you can easily create sub-domains and point them to Azure. As I start my journey and conduct real-world POC in Azure, I needed at least there applications to start with and people should be able to access them via custom domains- azure.aspnet4you.com (for user interface), api.aspnet4you.com (for RESTFul API) and blogs.aspnet4you.com (for documentations).

My case was little different than typical documentation provided at Azure. I did not want to change the A Record for my domain aspnet4you.com which is hosted at webhost4life.com. My requirement is to point CNAME (subdomain, azure.aspnet4you.com) to [mydomain].azurewebsites.net. My domain is registered at GoDaddy but the hosting is at webhost4life.com. Obviously, I configured the NS (name server) at GoDaddy which are managed by webhost4life.com. Question is where do I add/define the CNAME- at GoDaddy or at Webhost4life? A common perception is- you do add CNAME at the GoDaddy because it is where you registered the domain but that’s incorrect. Why? The Name Servers (NS) are at Webhost4life and NS knows the host server (IP). So, I have to add the CNAME (azure.aspnet4you.com) at Webhost4life and point it to aspnet4you.azurewebsites.net (name of my application at Azure). Keep in mind, you can have any name prefix at azurewebsites.net as long it is available. Use of my own domain as prefix guarantees the uniqueness.

Next, you go to Azure App Service Custom Domain and add a host. What host? A record or CNAME? Again, I don’t want to bring my main domain/site to Azure. So, I added the host as azure.aspnet4you.com, click on validate and added the host (make sure to click Add Hostname button!). That’s all it takes to make your subdomain point to azure.

It may take little time to propagate DNS records but we don’t have patience! Go to DOS Command prompt on windows and run ipconfig /flushdns. That should fix the dns resolution. Now you are ready to use the custom domain pointed to azure. Want to try it? Visit azure.aspnet4you.com!

 

Leave a Reply