Trying to redirect a docker container to another through nginx

6,184

the location should be / not \

and also try to put the other container name or it's IP in the proxy_pass

Share:
6,184

Related videos on Youtube

Radaeld
Author by

Radaeld

Updated on September 18, 2022

Comments

  • Radaeld
    Radaeld over 1 year

    As the title say trying to reverse proxy. Using an app with port 500 inside container with port exposed for 5000. The nginx is on another container with port 80 exposed and publish to 8080. Both containers are in the same network that I've created.

    On Nginx container I've deleted the default.conf and created a new one as follows:

    server{
      listen 80;
      location \ {
        proxy_pass "http:0.0.0.0:5000";
        proxy_set_header Host $host;
        proxy_redirect          off;
        proxy_set_header        X-NginX-Proxy true;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      }
    }
    

    I also restarted the nginx so it starts with this .conf

    when trying to access using the url: http://172.17.0.1:8080/ which is the gateway to the network i only get 404 not found. On the Nginx container i get this message

    "/etc/nginx/html/index.html" is not found (2: No such file or directory), client: 172.17.0.1, server: , request: "GET / HTTP/1.1", host: "172.17.0.1:8080"

    Its like he is not redirecting only searching for the index file of the default.conf

    Through nginx -T i can see that the configuration above is loaded. Any one can help with the forwarding of this?

    • ignivs
      ignivs about 5 years
      a typo here perhaps (or maybe the issue) > location \ { ... } the \ (backslash) is an escape character there, shouldn't be "/"?
    • Radaeld
      Radaeld about 5 years
      rip im dead. That was the forwarding problem. Although now i have a new error. Connection refuse. After using nmap to check if the exposed port of the container is open it seems filtered the 5000. As a result is refusinghte connection :/
  • Radaeld
    Radaeld about 5 years
    yea it was /. I the ip is correct since they are inside the same net work. But getting connection refused now (tried the docker ip of te network and did not work too just to be safe). New problem pop up.
  • Kerolos William
    Kerolos William about 5 years
    what's the output of you trying to telnet from inside the container to the other one's IP and port ?
  • Radaeld
    Radaeld about 5 years
    # telnet n2 5000 Trying 172.18.0.3... telnet: Unable to connect to remote host: Connection refused
  • Kerolos William
    Kerolos William about 5 years
    are you using publish or expose for the docker ports you can check the following URL for more help nickjanetakis.com/blog/…
  • Radaeld
    Radaeld about 5 years
    expose since its the same network, testing inside the nginx container