Please help me on this below issue in the app gateway request routing to backend app service (307-temporary redirected)

Arunsundhar Anbu (Augmento Labs) 0 Reputation points
2023-08-31T09:08:16.24+00:00

Please help me on this below issue in the app gateway request routing to backend app service (307-temporary redirected)

Below is the complete details with regards to the configuration.

We have configured backend pool by adding 3 different target web apps (1 for frontend service and rest 2 web app for different backend api services)

also we have configured listeners, backend settings and routing rules with path based routing for the backend api services.

We also configured custom domain to the default https listener used for with required SSL certificates.

Finally when we are trying to hit the custom domain the request is routing perfectly to the frontend web app, But when the request is routing to web apps which contains backend api services, we are facing 307-temporary redirected and in the next call request directly pointed to web app base URL which ends with azurewebsites.net instead of request going through app gateway (with custom domain), If any one faced same issue and resolved it, Please help us and its blocking our priority work items.

FYI

Network trace when the request routed to backend api

In the first call its giving 307- temporary redirected
appgw_307-temproary redirected_issue.JPG
appgw_second call to web app directly.JPG

For your reference Network traces images has been attached with this question

Please let me know if you need any details to solve this issue?

Early answer or response to resolve this issue will be greatly appreciated and unblocks lot of activity.

Regards,
ARUN

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,146 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,500 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. GitaraniSharma-MSFT 49,861 Reputation points Microsoft Employee
    2023-08-31T11:24:31.57+00:00

    Hello @Arunsundhar Anbu (Augmento Labs) ,

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

    I understand that you would like to know why you are redirected to the App service URL when you access the application gateway's custom domain in your browser.

    This is a known issue with reverse proxy and multitenant PaaS services.

    Multitenant PaaS services often require a registered and validated host name in order to route an incoming request to the appropriate tenant's back-end server. This is because there's typically a shared pool of load balancers that accept incoming requests for all tenants. The tenants commonly use the incoming host name to look up the correct back end for the customer tenant.

    To make it easy to get started, these platforms typically provide a default domain that's preconfigured to route traffic to your deployed instance. For App Service, this default domain is azurewebsites.net. Each web app that you create gets its own subdomain, for example, contoso.azurewebsites.net.

    Having a different host name at the reverse proxy (in our case, Application gateway) than the one that's provided to the back-end application server can lead to cookies or redirect URLs that don't work properly. For example, session state can get lost, authentication can fail, or back-end URLs can inadvertently be exposed to end users. This is what is happening in your case.

    You can refer the testing section of the below doc and you can see if you use default domain with App gateway IP or DNS, it redirects to the .azurewebsite.net directly instead of the App gateway.

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

    Back-end configuration or the changes required on your web app/App service:

    Since you are using an App Service, you can attach a custom domain name to the web app and avoid using the default azurewebsites.net host name towards the back end. You don't need to change your DNS resolution when you attach a custom domain to the web app: you can verify the domain by using a TXT record without affecting your regular CNAME or A records (These records will still resolve to the IP address of the reverse proxy/Azure Application gateway).

    Refer: https://learn.microsoft.com/en-us/azure/architecture/best-practices/host-name-preservation#back-end-configuration

    So, you should use the recommended solution of preserving the original HTTP host name when you use a reverse proxy in front of a web application. Follow the instructions for "Custom Domain (recommended)" in the below "Configure App Service with Application Gateway" document to solve this issue.

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

    Refer the below docs for more details on this issue:

    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-issues

    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.