0

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 2

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.

Sign up to request clarification or add additional context in comments.

8 Comments

Its working now thanks for pointing out the mistake is there any way where I can remove port as well because currently I am accessing at localhost:7070 so can I eliminate 7070 by any means.
Great that it worked for you. To eliminate the access of NGINX using localhost:7070, map it to port 80 so that http://localhost will resolve to port 80.
That I am mapping like this docker run -p 7070:80 --name nginx mynginx:1.0 at the time of starting the nginx container.
docker run -p <hostport>:<containerport> is the syntax. So, it should be docker run -p 80:80 to make it listen on http://localhost
What if I deploy these two containers over AWS ECS then would it requires remote server ip in place of windows ip is it correct?
|
1

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

1 Comment

What if I deploy these two containers over AWS ECS then would it requires remote server ip what I am understanding is.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.