Azure Application Gateway - Standard V2

Nitya V 45 Reputation points
2024-07-09T09:20:24.42+00:00

I have twoapp services that I want to use application gateway to sit in front of and route traffic to using URL Routing. For example:

  1. api1-app-service
  2. api2-app-service

I would like to use the Application Gateway without a custom domain in front of it, and route the traffic like this:

  1. appgateway-public-ip/d1/something -> api1-app-service
  2. appgateway-public-ip/d2/different -> api2-app-service

I have created a http listener type multisite with wildcard entry as *.azurewebsites.net

and routing rul which is path based
/d1/-> api1-app-service(backend pool and setting)
/d1/
-> api1-app-service(backend pool and setting)

However when I try http://<app gateway ip>/d001/explorer it give 404

how should it be configured

Azure Application Gateway
Azure Application Gateway
An Azure service that provides a platform-managed, scalable, and highly available application delivery controller as a service.
1,079 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. GitaraniSharma-MSFT 49,581 Reputation points Microsoft Employee
    2024-07-09T11:27:16.0866667+00:00

    Hello @Nitya V ,

    Welcome to Microsoft Q&A Platform. Thank you for reaching out & hope you are doing well.

    I understand that you would like to configure Azure Application gateway path-based routing to 2 app services in the backend without using a custom domain.

    You can find the step-by-step configuration of Application gateway with App service using default domain in the below document:

    https://learn.microsoft.com/en-us/azure/application-gateway/configure-web-app?tabs=defaultdomain%2Cazure-portal

    Now, coming to your requirement which is as below:

    1. appgateway-public-ip/d1/something -> api1-app-service
    2. appgateway-public-ip/d2/different -> api2-app-service

    For backend pool configuration:

    You need to create 2 backend pools : one containing the api1-app-service and other containing the api2-app-service.

    For Listener configuration:

    Then you can create a basic listener with the required port (you don't need to use multi-site listener as you will be using the default domain of the App service instead of a custom domain).

    For the backend settings:

    1. When creating a backend setting, give it a name
    2. Select HTTP/HTTPS as the desired backend protocol using port 80/443
    3. If using HTTPS/port 443, select "Yes" for "Backend server’s certificate is issued by a well-known CA".
    4. Make sure to set "Override with new host name" to "Yes"
    5. Under "Host name override", select "Pick host name from backend target". This setting will cause the request towards App Service to use the "azurewebsites.net" host name, as is configured in the Backend Pool.

    For Rule configuration:

    1. Under "Rules", click to add a new "Request routing rule"
    2. Provide the rule with a name
    3. Select an HTTP or HTTPS listener that is not bound yet to an existing routing rule
    4. Under "Backend targets", choose a default Backend Pool in which App Service has been configured
    5. Configure the HTTP settings with which Application Gateway should connect to the App Service backend
    6. Under Path-based routing:
    7. For Path, type /d1/*.
    8. For Target name, type a name.
    9. For HTTP setting, select your HTTP setting
    10. For Backend target, select the api1-app-service.
    11. Select Add to save the path rule and return to the Add a routing rule tab.
    12. Repeat to add another rule for api2-app-service.
    13. Select Add to add the routing rule and return to the Configuration tab.
    14. Select "Add" to save this configuration

    NOTE: The default backend target mentioned at the top of the rule handles the request for the default domain (/*) without any paths and the backend targets mentioned under the path-based routing handles the requests for the specific paths configured.

    By default, App Service starts your app from the root directory of your app code. But certain web frameworks don't start in the root directory. For example, Laravel starts in the public subdirectory. Such an app would be accessible at http://contoso.com/public, for example, but you typically want to direct http://contoso.com to the public directory instead. If your app's startup file is in a different folder, or if your repository has more than one application, you can edit or add virtual applications and directories.

    Refer: https://learn.microsoft.com/en-us/azure/app-service/configure-common?tabs=portal#map-a-url-path-to-a-directory

    Points to remember:

    This configuration comes with limitations. We recommend reviewing the implications of using different host names between the client and Application Gateway and between Application and App Service in the backend. For more information, please review the article in Architecture Center:

    Preserve the original HTTP host name between a reverse proxy and its back-end web application

    When App Service doesn't have a custom domain associated with it, the host header on the incoming request on the web application will need to be set to the default domain, suffixed with ".azurewebsites.net" or else the platform won't be able to properly route the request. The host header in the original request received by the Application Gateway will be different from the host name of the backend App Service.

    Refer: https://learn.microsoft.com/en-us/azure/application-gateway/troubleshoot-app-service-redirection-app-service-url

    https://learn.microsoft.com/en-us/azure/architecture/best-practices/host-name-preservation#potential-problems

    https://learn.microsoft.com/en-us/azure/application-gateway/url-route-overview

    https://learn.microsoft.com/en-us/azure/application-gateway/create-url-route-portal

    Kindly let us know if the above helps or you need further assistance on this issue.


    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.