"502 Bad Gateway" on Application Gateway when "Override with new host name" is disabled, redirect issues when enabled
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 tostaging.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?