Nginx proxy is not finding the backend services

docker-composenginx

I've an installation with 2 backend services that should be proxied by a third Nginx service.

I've deployed the 3 services succesfully but for some reason I can't get nginx to see the other 2 services giving the error:

GET / HTTP/1.1" 502 560

and

[error] 8#8: *1 no live upstreams while connecting to upstream

I have tried changing all the services to their own network but it seems the issue is not solved.

Adding my docker-compose.yml:

version: "3"
services:
    nginx_web_1:
        image: nginx:1.17
        volumes:
            - "./files_1:/usr/share/nginx/html:ro"

    nginx_web_2:
        image: nginx:1.17
        volumes:
            - "./files_2:/usr/share/nginx/html:ro"

    nginx_balancer:
        build: ./balancer
        ports:
            - 5000:80
        depends_on:
            - nginx_web_1
            - nginx_web_2

and this is how I configured the proxy:

File moved to /etc/nginx/conf.d/default.conf

upstream backend_hosts {
    server nginx_web_1;
    server nginx_web_2;
}

server {
    listen 80;
    server_name localhost;
    location / {
      proxy_pass http://backend_hosts;
    }
}

Best Answer

After some investigation, the issue was that I was running only docker-compose up/down which didn't rebuild my Nginx proxy image.

After cleaning up and running a docker build the proxy was configured properly and now runs fine.

That means that also the config listed in the question is a valid one