'404 error in url based routing using Application Gateway

I have 2 web apps behind Application Gateway. I am trying to access by http://<aap_gateway_pub_ip>/web1 should go to http://webapp1.azurewebsites.net and http://<aap_gateway_pub_ip>/web2 should go to http://webapp2.azurewebsites.net. I have defined path based rule like:

$web1PathRule = New-AzureRmApplicationGatewayPathRuleConfig -Name web1pathrule -Paths "/web1" -BackendAddressPool $regbackendpool -BackendHttpSettings $poolSetting

$web2PathRule = New-AzureRmApplicationGatewayPathRuleConfig -Name web2pathrule  -Paths "/web2" -BackendAddressPool $accbackendpool -BackendHttpSettings $poolSetting

$urlpathmap = New-AzureRmApplicationGatewayUrlPathMapConfig -Name urlpathmap -PathRules $web1PathRule, $web2PathRule -DefaultBackendAddressPool $defaultPool -DefaultBackendHttpSettings $poolSetting

$urlRoutingRule = New-AzureRmApplicationGatewayRequestRoutingRule -Name routingrule-001 -RuleType PathBasedRouting -HttpListener $defaultlistener -UrlPathMap $urlpathmap

The issue is when I directly access http://<aap_gateway_pub_ip> request goes to default pool which is web1 backendpool and opens web1 app. But when I access http://<aap_gateway_pub_ip>/web1, it returns 404 error.

What additional configuration is required to make this working?



Solution 1:[1]

I also got stuck in this problem for a day and trust me Microsoft should think about and adding more clear instructions.

The thing is when you access the base address of frontend IP like this http://<aap_gateway_pub_ip> It simply replace the frontend IP with the backend pool based web app IP, so the request sent to the web app is something like http://webapp1.azurewebsites.net and it works.

Problem starts when you create a path based rule and configure it like this http://<aap_gateway_pub_ip>/web1 -> http://webapp1.azurewebsites.net

What app gateway does, it simply replace the front end ip with the backend ip
So the request sent to backend is

http://webapp1.azurewebsites.net/web1

and if your backend webapp does not contain that page in the website then it will through 404 error.

So there are 2 solutions for that

1> Edit the httpsetting of the rule and add a '/' in the "override backend path"

Screenshot for HTTPSetting

2> The other approach is to actually drive the path based rule in such a way that the final path (like web1 in your case) should actually exists in the backend server or webapp.

Solution 2:[2]

Please follow additional backend http settings and probe configuration for integration with Web Apps to work correctly. The documentation is here.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Harsh
Solution 2 amsriva-msft