I have 2 separate docker containers node app and nginx running locally on windows machine.BBOth 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 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;
}
}
Someone let me know what I am doing wrong. Any help is appreciated.
CodePudding user response:
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.
CodePudding user response:
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