Issue with nginx reverse proxy to FastAPI container in Azure Container Apps

Joris 10 Reputation points
2024-11-01T11:04:36.45+00:00

Hi,

I'm trying to setup an nginx reverse proxy on Container Apps. I have the nginx container and a FastAPI container in a Container App Environment with simple virtual network + subnet + private DNS zone. The API's ingress is set to internal, and the nginx ingress to external.

When I go to the nginx URL I get:

"Error 404 - This Container App is stopped or does not exist."

Though I'm able to verify that I can reach the nginx container's by making it serve a local html file on /nginx. (see config below)

When I attach to the nginx Container App on Azure, I am able to curl the API at http://api-container:80 and get the expected response.

This makes me think there's an (Azure-specific?) problem with the nginx configuration, since it does work locally with Docker Compose.

Some advice would be much appreciated! I can post my nginx config but it appears I can't post it in this question because it becomes too long.

Azure Container Apps
Azure Container Apps
An Azure service that provides a general-purpose, serverless container platform.
686 questions
{count} vote

1 answer

Sort by: Most helpful
  1. Joris 10 Reputation points
    2024-11-05T08:29:58.84+00:00

    had to manually set the Host header to the hostname (the container name in my case):

    proxy_set_header Host chat-ui;  # Set Host header explicitly to chat-ui
    

    When I ran a nslookup <api-container-name> from within the nginx container, I noticed that curl <resolved-ip-address> gave a 404, while a curl <api-container-name> got me a 200.

    I don't entirely understand what's going on, but it seems Azure's internal routing system uses the Host header to find the right service, and the internal IP of that service is not meant to be used directly. I guess nginx sets the Host header to itself rather than the container it's forwarding to.

    If anyone has a better explanation, let me know!

    1 person found this answer helpful.
    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.