Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

159
Visualizações
Nginx container as a proxy to another docker container localhost - 502 BAD gateway

I have a container which runs its web app on localhost:4000 i want to access it through nginx which is in another container. I have created a docker network and ran the following to bring them under same network mynetwork

docker run --name myapp -p 8080:4000 -d --network mynewnetwork ubuntunet:1.9 --- myapp

docker run --name nginx -p 80:80 -d --network mynewnetwork nginx --- nginx

with the following nginx.conf

worker_processes 1;

events { worker_connections 1024; }

http {

    sendfile on;

    upstream docker-myapp {
        server myapp:4000;
    }

    server {
        listen 80;    
        location / {
            proxy_pass         http://docker-myapp;
            proxy_http_version 1.1;
            proxy_redirect off;
            proxy_set_header   Upgrade $http_upgrade;
            proxy_set_header   Connection keep-alive;
            proxy_set_header   Host $host;
            proxy_cache_bypass $http_upgrade;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Proto $scheme;
        }
    }

}

For some reason this is not working showing 502 bad gateway when i access docker host ip, when we create a docker network it opens all ports between the containers that resides in the same network correct? if yes why my app is not running. Should i change hosts file in myapp container to have docker ip with localhost instead of 127.0.0.1? or i am missing something in this. Any help on this would be appreciated.

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda