2

Setup: All following are running on my Mac OS:

localhost:8089 a nodejs REST api runing in my local, OUTSIDE of the nginx container, stand alone!

locahost:80 nginx docker container

I was able to serve static file inside the nginx docker container, but when I set the config for the nginx as:

http {
    server {
        location / {
            root /usr/share/nginx/html;
        }
        location /api/ {
            proxy_pass http://localhost:8089;
        }
    }
}

for some reason, any localhost:80/api call that suppose to direct to http://localhost:8089; call is returning 404 not found page

404 Not Found

nginx/1.13.6

Any idea where is the config I made wrong? I feel like maybe I shouldn't use localhost:8089 inside nginx? But then what should I be using?

An example can be found here https://github.com/adamchenwei/docker-nginx-playground

Ezeewei
  • 6,347
  • 7
  • 50
  • 98

1 Answers1

3

Containers have their own networking namespace / networking stack. So localhost inside the container is the localhost of the container itself.

If you are running Docker for Mac, there is a special hostname that's available inside the container that allows you to connect to services that are running on the host itself. Refer to this answer for more information; https://stackoverflow.com/a/43541732/1811501

If you are running Docker on Linux, this answer (on the same question) allows you to find the IP-address to connect to; https://stackoverflow.com/a/31328031/1811501

thaJeztah
  • 23,621
  • 8
  • 58
  • 85