"502 Bad Gateway" on Application Gateway when "Override with new host name" is disabled, redirect issues when enabled

Muhammad Elzedy 0 Reputation points
2024-09-28T15:49:09.3566667+00:00

Hello,

I am creating an Application Gateway to forward traffic to an Azure App Service with the domain: aladwaa360.azurewebsites.net. However, I’m facing two issues with the host name override feature:

502 Bad Gateway with host name override disabled: When I access the Application Gateway's public IP, I receive a "502 Bad Gateway" error if the "Override with new host name" option is set to No in the backend settings.

Redirection issue with host name override enabled: When I set the "Override with new host name" option to Yes, the gateway works, and I can access the app service through my custom domain (staging.example.com). However, I encounter a new issue related to redirection.

  • I have a login form on the app service. Upon successful login, it should redirect me to the main app at staging.example.com. However, what happens instead is:
    - After logging in, the URL briefly changes to `staging.example.com` but then quickly redirects back to the default App Service URL (`aladwaa360.azurewebsites.net`).
    

Configuration Details:

  • I’ve set up a custom domain for the Application Gateway: staging.example.com.
  • The login form sends me to another application (hosted on staging.account.example.com) and is supposed to redirect back to staging.example.com after successful login.

Goal: I need to ensure that, after logging in, the browser's URL remains as staging.example.com (instead of reverting to the default aladwaa360.azurewebsites.net). Additionally, I plan to route traffic based on the URL path (e.g., /qrcode should route to a different backend service).

Questions:

  • Why does this redirection back to the default app service URL happen?
  • How can I ensure that the custom domain (staging.example.com) remains in the browser's address bar, even after logging in?
  • What is the best way to set up the Application Gateway to handle routing traffic to different backends based on the path?
Azure
Azure
A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.
1,041 questions
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,063 questions
0 comments No comments
{count} votes

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.