0
votes

im very new with this docker thing, im trying create a load balancer of 2 server, the first port is localhost:2222 and localhost:3333, it can be accessed properly.

    http {
    upstream all {
        server 127.0.0.1:3333;
        server 127.0.0.1:2222;
    }
    server{
        listen 8080;
        location / {
            proxy_ssl_server_name on;
            proxy_pass http://all/;
    
    
        }
    }
}
events {}

but when i try integrate it with nginx load balancer with this configuration. with localhost:8080 as listener, it cannot be accessed it always displayed 502 bad gateway and the nginx shown this error

2021/12/04 10:04:23 [error] 32#32: *4 connect() failed (111: Connection refused) while connecting to upstream, client: 172.17.0.1, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:2222/", host: "localhost:8080"

2021/12/04 10:04:23 [error] 32#32: *4 connect() failed (111: Connection refused) while connecting to upstream, client: 172.17.0.1, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:3333/", host: "localhost:8080" 172.17.0.1 - - [04/Dec/2021:10:04:23 +0000] "GET / HTTP/1.1" 502 157 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:93.0) Gecko/20100101 Firefox/93.0"

2021/12/04 10:04:27 [error] 32#32: *4 no live upstreams while connecting to upstream, client: 172.17.0.1, server: , request: "GET / HTTP/1.1", upstream: "http://all/", host: "localhost:8080" 172.17.0.1 - - [04/Dec/2021:10:04:27 +0000] "GET / HTTP/1.1" 502 157 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:93.0) Gecko/20100101 Firefox/93.0"

anybody know how to solve it? i have been struggling this for a long time

Nginx isn’t running in a container but in the host machine?Sami Kuhmonen
nginx running in the container but separated from the web containerfurqon2710
Do not use loopback address(127.0.0.1). If you expose container port, use host ip address. Or link containers and use container name rather than loopback address.J. Song