Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!