5

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
  • 315
  • 2
  • 16

3 Answers3

3

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
  • 315
  • 2
  • 16
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,429
  • 11
  • 23
0
http
{
server {        
        ssl_certificate         /etc/tls/tls.crt;
        ssl_certificate_key     /etc/tls/tls.key;

        resolver 127.0.0.11;
        resolver_timeout      10s;

        access_log              /var/log/nginx/access_log.log;

        location / {
                set             $upstream_app homer;
                set             $upstream_port 8080;
                set             $upstream_proto http;
                proxy_pass      http://localhost:7001;
        }
}
}

i worked too

ihsan güç
  • 241
  • 3
  • 7