3

I use an nginx container with this config:

set $ui http://ui:9000/backend;
resolver 127.0.0.11 valid=5m;
proxy_pass $ui;

This is needed, because the "ui" container wont necessarly be up when nginx starts. This avoids the "host not found in upstream..." error.

But now I get a 404 even when the ui-container is up and running (they are both in the same network defined in the docker-compose.yml). When I proxy pass without the variable, without the resolver and start the ui container first, everything works.

Now I am looking for why docker is failing to resolve it. Could I maybe manually add a fake route to http://ui which gets replaced when the ui-container starts? Where would that be? Or can I fix the resolver?

Vertago
  • 169
  • 1
  • 14

2 Answers2

2

The answer is like in this post:

https://stackoverflow.com/a/52319161/3093499

Only change is putting the resolver and set variable into the server-body instead of the location.

Vertago
  • 169
  • 1
  • 14
0

First you need to make sure that you have the port in the ui backend Dockerfile with EXPOSE 9000. Then you're going to want to have this as your config:

http {
  upstream ui {
    server ui:9000;
  }

  server {
    # whatever port your nginx reverse proxy is listening on.
    listen 80;

    location / {
      proxy_pass http://ui/backend;
    }
  }

Billy Ferguson
  • 1,369
  • 10
  • 21