How to add Azure App Service redundancy using Application Gateway? - azure-web-app-service

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.

Related

Azure Application Gateway: Why when i hit its Public IP, i redirect to "<app_service_url>:80"?

I have an app service which runs web app.
I created application gateway on the front of wab app.
But when i hit Application Gatway's Public IP, i get redirected to https://somename.azurewebsites.net:80/
My Questions
Why it does not goes to go <ApplicationGatwayPublicIP> directly instead of https://somename.azurewebsites.net:80/
Let's assume that i accepte to https://somename.azurewebsites.net:80/. Why it adds 80 at the end (which i have to delete manually in oreder to work)?
Thank you in advance for your help!
PS: I will make some screenshot which can be helpul:
Backend Pool (app service):
Backend Settings (for app service):
If you need more informations, please make me a comment
Thank you again
To resolve this issue, you need configure your backend pool with use of custom domain as below:
Make sure to add authentication/trusted root certificates of back-end servers and upload a certificate as below:
And configure a request to routing rule in setting under rules in backend targets try to add the Backend Pool which App Service has been configured and HTTP setting add which app gateway to connect app service and save
Once a backend pool is healthy stage now you can able to use public IP addresses that can be accessed directly. Now you can try to restrict access. check this similar issue answer by jeremy
The main cause of issue you need to add custom domain Configure App Service with Application Gateway along with certificate.
Reference:
Manage traffic to App Service - Azure Application Gateway | Microsoft Learn

Application Gateway Url Routing to multiple App Services

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.

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.

How do you add a web app to the backend pool of Azure Application Gateway?

I have created a Webapp and have added an IP restriction so that it can only be accessed via the Azure Application Gateway Public IP.
In the Application Gateway, I navigated to the BackEnd Pools, clicked to ADD backend pool and copied the web app URL e.g. https://mywebapp.azurewebsites.net, it complained it only wanted FQDN so I removed the https:// and entered in mywebapp.azurewebsites.net
I then navigated to my Application Gateway and copied the public IP address of the gateway and entered it in my browser to test the app but it won't see the web app, I get the error "This site can’t be reached."
Have I missed a step, is the FQDN incorrect? Do I need to use a custom Domain?
One of the things I would look for is if a listener and a rule has been created. This is required to enable the application gateway to route traffic appropriately to the backend pool.
More info here -
https://learn.microsoft.com/en-us/azure/application-gateway/application-gateway-web-app-powershell
I tried adding an existing app service web app to the backend pool like you mentioned and realized that it was not adding the listener/rule for it. When i used the powershell script as mentioned in the link above which creates a listener and a rule , i was able to successfully hit backend pool website when i browsed using the Application Gateway public ip/dns.
https://learn.microsoft.com/en-us/azure/application-gateway/application-gateway-create-gateway-arm

What is the Best way to Load balance Azure web apps deployed under one Azure App Service plan

I have 1 Webapp running under same App service plan. As I am using a premium Azure app service plan with 15 instances, We are consuming only 10 percent of CPU. So to increase more availability and responsiveness of our app, I was planning to deploy one more instance of same app with a different name under same App service plan.
So now I am running my-app and my-app01 under 1 app service plan. Now I want to distibute the incoming traffic between this 2 apps.
As this app's are running under on app service, they are running on same location. So Azure Traffic manager doesn't allow the endpoints from same location. To by pass this I have used Traffic manager nested nedpoint to list my both app endpoints under one traffic manager.
then I have added my custom domain name to traffic manager as a CNAME record mapping.
myapp.abhisqs.com -> abhisq.trafficmanager.net -> (my-app.azurewebsites.net , my-app01.azurewebsites.net)
After doing this I am not able to open my app by hitting https://myapp.abhisqs.com/pages/default.aspx from Url, it was throwing 403 error. So I added a hostname(myapp.abhisqs.com) and SSL binding for my-app. Then I was able to open my app by using the https://myapp.abhisqs.com/pages/default.aspx.
So Now my other app instance my-app01 doesn't have a Hostname and SSL binding, So if my primary app (my-app) is off, then I am not able to open the app UI ( fails with error 403). Also from Azure portal I am not able to add host name and SSL binding to my second app which is running under same app service plan. It throws error "the host name 'myapp.abhisqs.com' is alredy configured for my-app so first remove that then configure with this."
So my question is what is best way to have multiple apps under same service plan, load balanced under one single custom domain name.

Resources