Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

160
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda