Application Gateway Url Routing to multiple App Services - azure

I have several app services that I want to use application gateway to sit in front of and route traffic to using URL Routing. For example:
api1-app-service
api2-app-service
website1-app-service
I would like to use the Application Gateway with a custom domain in front of it, and route the traffic like this:
test.app.com/api/something -> api1-app-service
test.app.com/api/different -> api2-app-service
test.app.com/ -> website1-app-service
I setup 3 different backend pools and a url routing rule that looks like this:
rule1 | /api/something* | backendPool1
rule2 | /api/different* | backendPool2
default rule | backendPool3
The problem I am having is that the direction here (https://blogs.msdn.microsoft.com/waws/2017/11/21/setting-up-application-gateway-with-an-app-service-that-uses-azure-active-directory-authentication/) says that the app service has to be setup with the custom domain that you are pointing to the application gateway (test.app.com in my example), but I can't configure test.app.com to go to multiple app services. I get an error that the hostname is already mapped to another app service (which is true, when trying to map to api2-app-service test.app.com is configured to api1-app-service). Is is possible to setup an application gateway in front of multiple app services?

It's possible to setup an application gateway in front of multiple app services.
If you want custom domains with your web app service, you could configure different custom domains in different App services. Probably, if you'd like to use the same custom domain, you could deploy multiple Applications in the same web app service with different virtual paths.
If you do not want custom domains in multiple App Services, you could use the default hostname *.azurewebsites.net. If so, the Application Gateway frontend will direct the client request to different backend pools based on the different routing rules. You could configure for the backend HTTP setting using -PickHostNameFromBackendAddress.
Ref: Hosting multiple sites in one Azure WebApp and create an application gateway with path-based routing rules.

After researching all day, I am fairly sure this isn't possible using just an Application Gateway and app services. I am going to containerize my app and then use the application gateway and see if that does what I want it to.

Related

How to add Azure App Service redundancy using Application Gateway?

what is the recommended best practice for using Azure Application Gateway with redundant app services (in either different regions or availability sets)? I've had some issues recently where our app service would occasionally go down for a couple minutes (due to maintenance in msft's data center) and I'd like to have our app gateway redirect load to another instance or app service when this happens.
Currently traffic is handled as such: public request -> app.example.com -> app gateway -> app.example.com -> backend app service.
I've been unable to add a second app service because when I attempt to do so I get the error "Hostname is already being used in the following App: myappservicename. Please remove the Hostname from myfirstappservice, and try again" when I attempt to add the custom domain to a second app service. It seems my custom domain would need to be added to each individual app service in order for traffic to be routed properly to my backend web app. Or is there another way I should have traffic configured?
You should bind your custom domain to your app gateway only and add your two app services into a backend pool so that the traffic could be:
public request -> app.example.com -> app gateway ->backend pool(handled by one of your 2 app services)
which meets your requirement.

Have you done single domain with multiple web apps in different paths?

So I'm trying to use Application Gateway in Azure and trying to do the following:
Single domain (app.mydomain.com) with path based routing to different web apps
like: http://app.mydomain.com/app1
http://app.mydomain.com/app2
Any idea how to configure it in Application Gateway?
I'm keep getting 502 Error when I did the routing to my web apps.
Any idea how to configure it in Application Gateway?
If you want to use path-based routing in the Application Gateway.
Sure, it is possible.
We can use the routing rules to point to a specific backend pool. That backend pool will point to whatever servers you want handling that request.
For more information you could following this tutorial. And you also could refer to this blog to get more detail steps

is it possible for 2 domain names to use one azure web app with application gateway and how?

I have 2 domains I want to use with one web app. I want all traffic to be routed via the app gateway.
I have set up 2 example domains www.myfirstdomain.com www.mysecondomain.com
I have verified these websites in my azure web app and added each hostname to the web app.
I have created virtual directories in the web app as follows
/one -> site\wwwroot\one
/two -> site\wwwroot\two
When I type in www.www.myfirstdomain.com I want this to go to the /one directory when I type in www.myseconddomain.com I want this to go the /two directory
Does the app gateway need to have multi site listeners and path based rules, is only one backendpool required?
In Azure the concept of a web server is the underlying App Service Plan, on top of that each virtual directory is a web app. You can have multiple web apps per Service Plan. So the usual solution is to have a separate web app for each distinct website you have. You can attach multiple domain names to each app, but they will all point to the same code.

Configuring Azure Application Gateway to Azure web app to route requests by path

I have two web apps (webapp1 and webapp2). I would like to use Application Gateway features where can route using path based redirect.
http://mywebsite/login1 redirect to webapp1
http://mywebsite/login2 redirect to webapp2
Is this possible it possible to do this with Application gateway if so can you please give link or direction on how to do this for web apps prespective
Yes, it is. You can use path-based routing in the Application Gateway to do the job. Here is the link:
Application Gateway URL Routing
The main idea is that you can use the routing rules to point to a specific backend pool. That backend pool will point to whatever servers you want handling that request.
Is this possible it possible to do this with Application gateway
Sure. If you want to do that with Azure WebApp service. But there are two things that we need to do:
1.Make sure that the application root path is the same as you mapped in the Application Gateway. For instance:
if you want route http://mywebsite/login1 -> webapp1
Your webapp1 application root path(home page) should be :http:///login1 You can do quick config at your app service - > Application settings -> Virtual applications and directories:
2.Two custom health prob is needed for Azure web apps , we could use PS script to create them since it seems there is no way to create them on Azure portal.
For more detail information, please refer to this blog.

Mapping two app service to one DNS in azure

I have two app services. One for UI and one for web api. I need to create a DNS so that I should be able to access like www.example.com/ui and www.example.com/api. Please let me know anyone how to achieve this without virtual directory concept.
Thanks
You cannot achieve this purely with DNS. DNS knows nothing about routes, only domain names. So www.example.com must resolve to one service, which should be your reverse proxy, maybe Application Gateway?
Here's the tutorial on hosting two apps behind Application Gateway: Tutorial: Create an application gateway that hosts multiple web sites using the Azure CLI.
Multiple-site hosting enables you to configure more than one web site on the same application gateway instance. This feature allows you to configure a more efficient topology for your deployments by adding up to 20 web sites to one application gateway. Each web site can be directed to its own pool. For example, application gateway can serve traffic for contoso.com and fabrikam.com from two server pools called ContosoServerPool and FabrikamServerPool.

Resources