Azure App Container and App Gateway - "host name" is not correct

Valentino 0 Reputation points
2024-07-11T16:55:19.36+00:00

I've implemented a Container App with an Application Gateway on Azure. In the Application Gateway, the "Backend Setting" configuration is set as follows:

  • "Override with new host name" = "Yes"
  • "Host name override" = "Pick hostname from backend target"

Using the Application Gateway Public IP, I can correctly visualize the website.

However, when clicking on a link, I receive a "wrong page" error because all relative URLs contain the Container App URL (e.g., https://container-app-name1.orangeglacier-859ee193.italynorth.azurecontainerapps.io) instead of the Application Gateway IP.

I've also tried to print the $_SERVER['HTTP_HOST'] variable and it contains container-app-name1.orangeglacier-859ee193.italynorth.azurecontainerapps.io.

What could be causing this issue and how can I ensure that all relative URLs use the Application Gateway IP?

Thank you!

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
Azure Container Apps
Azure Container Apps
An Azure service that provides a general-purpose, serverless container platform.
440 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. KapilAnanth-MSFT 46,776 Reputation points Microsoft Employee
    2024-07-12T05:07:41.0433333+00:00

    Valentino,

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

    This looks like the backend is sending an absolute path instead of a relative path to the client.

    And hence, the client is sending the requests to the original path instead of the App Gateway's IP.

    i.e.,

    • Say the App Gateway is being accessed like http://<AppGwIp>/abc/xyz and you select/click a file called "file.txt" from browser client.
    • The server, instead of sending a response like "/abc/xyz/file.txt", it responds "http://container-app-name1.orangeglacier-859ee193.italynorth.azurecontainerapps.io/abc/xyz/file.txt"
    • When this happens, the client now is redirected to the actual site instead of the reverse proxy which is App Gateway.

    You can find more details on this here : Potential problems - Incorrect absolute URLs

    This also leads to problems such as

    • Incorrect redirect URLs
    • Broken cookies

    In fact, the entire document Host Name Preservation explains why using such a configuration is not desired and recommends you use a custom domain.

    See : Implementation guidance for common Azure services

    • User's image
    • i.e., Host Name should be "preserved" and not modified
    • For App Gateway,

    If you use Application Gateway as the reverse proxy, you can ensure that the original host name is preserved by disabling Override with new host name on the back-end HTTP setting. Doing so disables both Pick host name from back-end address and Override with specific domain name. (Both of these settings override the host name.)

    Because health probes are sent outside the context of an incoming request, they can't dynamically determine the correct host name. Instead, you have to create a custom health probe, disable Pick host name from backend HTTP settings, and explicitly specify the host name. For this host name, you should also use an appropriate custom domain, for consistency. (You could, however, use the default domain of the hosting platform here, because health probes ignore incorrect cookies or redirect URLs in the response.)

    In your case, I see backend is Azure Container Apps,

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

    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.

    0 comments No comments

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.