I'd like to use path based routing to my azure app service web apps so that
http://mysite.mydomain.com/site1 points to http://mysite1.azurewebsites.net http://mysite.mydomain.com/site2 points to http://mysite2.azurewebsites.net
What is the best way to do this? (I'd like to keep two app services. Not packing two apps in one as virtual directories)
I've tried using Azure Application Gateway which can be configured for this but then I couldn't configure the Web apps to accept traffic from the same custom domain.
In summary this is what I did:
The DNS record for mysite.mydomain.com points to the Application gateway's FQDN with a CNAME record
Application Gateway is configured so that :
http://mysite.mydomain.com/site1 points to http://mysite1.azurewebsites.net http://mysite.mydomain.com/site2 points to http://mysite2.azurewebsites.net
In order for the web apps to respond to this redirected request, they need to be configured with a custom domain. Since the CNAME record for mysite.mydomain.com points to the Application Gateway, I can't move this to the web apps. Because of this I've added a TXT record and added
awverify.mysite1 pointing to http://mysite1.azurewebsites.net
This was enough to make the first route work. Now http://mysite.mydomain.com/site1 happily returns responses from the 1st app service web app.
However, when I did a similar configuration for the second site. The 2nd web app refused to accept the same custom domain as the first one saying:
Hostname is already being used in the following App: mysite1. Please remove the Hostname from mysite1, and try again.
So how do I add the same custom domain to two app service web apps so that they can be used in a scenario like this?
This is possible by implementing reverse proxy feature via URL rewrite module in Azure web apps. Refer to Ruslan's blog post here: http://ruslany.net/2014/05/using-azure-web-site-as-a-reverse-proxy/
This is a 2 step process: