skip to Main Content

I have 2 separate Docker containers: Node app and Nginx running locally on a Windows machine. Both containers are up and running but I am unable to access my Node app via reverse proxy that I have set up in Nginx:

Node app container is ruuning using below command:

docker run -p 2020:2020 --name nodeapp myimage:1.0

Node app is accessible at localhost:2020 url

For the Nginx container I am using

docker run -p 7070:80 --name nginx mynginx:1.0

Nginx is accessible at localhost:7070

Below is my nginx configuration file:

default.conf

upstream nodeserver {
  server 127.0.0.1:2020;
}
server {  
  location / {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded_Proto $scheme;
    proxy_pass http://nodeserver;
  }
}

What am I doing wrong?

2

Answers


  1. 127.0.0.1 from inside the docker will resolve to it’s own localhost and not the Window’s localhost.

    Update the server 127.0.0.1:2020; to server <Windows server IP>:2020;. It should work.

    Login or Signup to reply.
  2. According to the previous answer yes, you should use Windows ip. Docker communicates each other with his containers using localhost ip, but outside container you should use Windows ip that should be:

    192.168.99.100
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search