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
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;
toserver <Windows server IP>:2020;
. It should work.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: