Welcome to the Microsoft Q&A Platform. Thank you for reaching out & I hope you are doing well.
I understand that you are facing issues with HostName while using a reverse proxy such as Application Gateway.
Your case is a classic and is explained here : Preserve the original HTTP host name between a reverse proxy and its back-end web application.
- This is more of a design issue rather than Application Gateway or Backend App Service's configuration issue.
- The exact issue is : Incorrect redirect URLs
This is why you are being redirected to the App Serice instead of the App Gateway (reverse proxy).
Now to answer your queries,
1 . Why does this redirection back to the default app service URL happen?
- I believe the document I shared above explains this issue.
2 . How can I ensure that the custom domain (staging.example.com
) remains in the browser's address bar, even after logging in?
- The recommendation is to have a single/same domain in both the App Gateway and the backend App Service.
- i.e.,
- Add a custom domain to AppService : Map custom DNS name to Azure App Service
- And make the custom domain resolve to the IP of the App gateway
- This way, both the service and the App Gateway will have the same domain "staging.example.com" and there is no redirection in the first place.
- i.e., all URLs become same
- Make sure to update your Identity providers with the URL of the App Service as "staging.example.com" and not the default "<AppServiceName>.azurewebsites.net"
See : Implementation guidance for common Azure services
If you host your web application in App Service, you can attach a custom domain name to the web app and avoid using the default
azurewebsites.net
host name toward 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 aTXT
record without affecting your regularCNAME
orA
records. (These records will still resolve to the IP address of the reverse proxy.)
3 . What is the best way to set up the Application Gateway to handle routing traffic to different backends based on the path?
- See : URL Path Based Routing for concepts
- To create path-based routing rules, refer here
Hope this clarifies.
Thanks,
Kapil
Please don’t forget to close the thread by clicking "Accept the answer" wherever the information provided helps you, as this can be beneficial to other community members.