2

Within a docker container I have a development server running that runs at:

http://127.0.0.1:8000/

Via nginx I am trying to make a request to this server:

nginx.conf

upstream service_rest {
    server restapi:8000;
}

server {

    location /rest/ {
        proxy_pass http://service_rest;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
    }
}

My understanding would be this:

  1. When I type localhost:9000/rest/ (port 9000 is exposed to my host machine and mapped to the nginx docker service) nginx looks upstream to the service_rest server on port 8000 --> this part works
  2. service_rest:8000 automatically "knows" that the request is for the development server running on http://127.0.0.1:8000/ inside the container

Here is the problem, though: I don't think the requests are ever passed to the server running on http://127.0.0.1:8000/

I recieve the following message as a log:

nginx_1 | 2019/05/11 07:49:06 [error] 6#6: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.32.1, server: , request: "GET /rest/admin/ HTTP/1.1", upstream: "http://192.168.32.2:8000/rest/admin/", host: "localhost:9000"

http://192.168.32.2:8000/rest/admin/ (ip of container in bridge network) obviously is not equal to http://127.0.0.1:8000/ even though I sort of thought they were?

I am quite new to docker and nginx and a little confused about this. Can you guys help?

0

For interested parties:

The trick was to not have the development server run on localhost but instead on:

0.0.0.0:8000

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.