Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Map subdomain to virtual directory Azure WebApps

I am attempting to host multiple websites in a single Azure WebApp rather than having multiple web apps each hosting a site. Each of these sites is rather small, but in order to meet the requirements of the SLA with Azure, we need to have the server scaled with more than one instance for our Production environment, thus the reasoning for combining sites.

After researching this topic, I have got the following setup with our Azure account.

  1. Created the proper CNAME DNS records in our zone manager (complete and works).
  2. Setup the Azure WebApp to respond to the subdomains (complete and works).
  3. Setup a virtual directory for the second web application (complete and works)

At this point, both web applications function correctly and both subdomains are pointing at our Azure instance. We now have the following setup:

  • both www.mydomain.com and app.mydomain.com bring up the root application that I deployed.
  • going to www.mydomain.com/app2 and app.mydomain.com/app2 bring up the second application that I deployed to the virtual directory

What I would like to achieve:

  • Going to app.mydomain.com would bring up the application in the virtual directory.
  • Going to www.mydomain.com would bring up the application at the root of the azure instance.

However, what I cannot figure out is how to map a subdomain to a specific virtual directory. I have tried to update the Site URL to be the subdomain I want the application to respond to, however, the subdomain still brings up whatever I have in the root of the WebApp deployment.

Should I have some HttpHandler that sits in the site root and directs traffic to the proper virtual directory? Is there a setting in the portal that I am missing? Previously, we did this with Web Roles and tinkering with the ServiceDefinition file, but the tool sets for the Azure Web Apps in regards to publishing, integration with Source Control, etc seem to be a bit further along.

like image 340
Tommy Avatar asked Oct 05 '15 15:10

Tommy


People also ask

How do I map an IP address to a domain name in Azure?

Create an alias record that points to the public IP address. In the Azure portal, enter contoso.com in the search box at the top of the portal, and then select contoso.com DNS zone from the search results. In the Overview page, select the + Record set button. In the Add record set, enter web01 in the Name.

What is Asuid?

The asuid TXT record is used by Azure to verify ownership of your domain. Once done configuring the DNS record with your registrar, return to the Azure portal, and click the Validate button on the Add custom domain blade. If everything goes well, your domain is now registered with your Web App.


1 Answers

The answer posted by RuslanY will work (with some modifications to the rules slightly) however, after understanding more of the Azure portal and Web App configurations, it is not needed to host multiple sites within a single Web App (Its technically multiple web apps all sharing the resource plan you define, such as 2 instances of Standard Level 0 (S0))*.

As of today's Azure service offerings, the following is true. When you create a new Web App, you pecify the "App Service Plan" that the app falls into. If you have an App Service plan, lets say Standard with 2 instances, any Web App you deploy to that App Service plan shares those resources with other web apps in the same service plan, meaning you are not paying additional costs to host the additional web app if it is in the same App Service plan. I had assumed each web app was its own set of resources (it can be, but doesn't have to be). Given this, to accomplish what I need, I simply create a web app for each sub domain and place them all into the same App Service plan. I now am hosting multiple sites, not paying for 2 servers per site (what I wanted to avoid) and I don't have to use URL rewrites or HTTP Handlers.

I hope this write-up helps others understand the structure of the Azure Web Apps a little bit better. The current online documentation, from what I can tell, doesn't make this exactly clear.

like image 167
Tommy Avatar answered Oct 13 '22 17:10

Tommy