In my previous blog, I had shown you how to create a azure web app with domain service enabled. if you notice the URL of the app, which is not at all user friendly, has domain name as “azurewebsites.net” and app name has some numeric figures attached to it (generally). It does not look relatable and gives rise to questions such as,
What if I need to map a custom domain name?
What if I need to change the app name?
In this blog, I will answer these questions. So, let’s get started.
One easy solution to the second question is that we should try and give a meaning full name while creating the app, but practically its difficult to get the name that we want because worldwide developers are using azure to create their apps. Another way of dealing with the challenge, which will solve both the issues, is using DNS records. We will use 2 types of DNS records.
Types of DNS records:
- A records
- CNAME records
These records are used to map custom domains to your azure web apps. DNS records are created by using the UI which your hosting partner provides. By using any one of these we can solve our purpose. For example “www.xyz.com” has a hosting on “Godaddy.com”, so to map the custom domain “xyz.com” to their azure web app, XYZ company will go to cpanel of their website provided by “Godaddy.com” and locate DNS setting to create the records.
Steps to create A records:
It maps custom domain to virtual IP address of Azure web app.
- Go to azure portal, click on your web app in the “app service” menu.
- Under the “Settings” option click on “Custom Domain”.
- Note down the IP address shown on the screen.
- Go to your website’s cpanel, under DNS setting select the domain you need to map and create A record wherein we will map www.xyz.com or a subdomain of xyz.com to the IP address.
- Open the screen from where we got the IP address(i.e. from the azure portal) and click on “Add Hostname” to get “Add Hostname” screen.
- Enter the hostname (www.xyz.com) and click on “validate”. It confirms that you own this hostname by checking the record you have put-in in the above steps.
- Successful validation enables “Add Hostname” button, click on the button to complete the process.
The hostname just mapped might take time to populate under “custom domain” section. For me it took around 20 mins.
Steps to create CName records:
It maps custom domain to azure web app’s domain name. It is as good as giving an alias.
- Go to azure portal and note down the web app’s URL. It is like “abc182017.azurewebsites.net”.
- Go to your website’s cpanel, create a subdomain for example “app.xyz.com”.
- Create CName record wherein we will map “app.xyz.com” to “abc182017.azurewebsites.net”.
- Follow the steps 5-7 to add hostname, as shown to create A record.
Congratulations!!! you have given a user-friendly name to your azure app. I prefer to give CName because it holds good even if we change the pricing plan of our app, since changing the plan or restarting the web app might change the IP address of the app, in which case we need to change the IP address in the cpanel for A record.