Dockercompose, Nginx, Resolver not working

Viewed 6835

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?

2 Answers

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;
    }
  }

Related