Trying to redirect a docker container to another through nginx
the location should be /
not \
and also try to put the other container name or it's IP in the proxy_pass
Related videos on Youtube
Radaeld
Updated on September 18, 2022Comments
-
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 about 5 yearsa typo here perhaps (or maybe the issue) > location \ { ... } the \ (backslash) is an escape character there, shouldn't be "/"?
-
Radaeld about 5 yearsrip 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 about 5 yearsyea 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 about 5 yearswhat's the output of you trying to telnet from inside the container to the other one's IP and port ?
-
Radaeld about 5 years# telnet n2 5000 Trying 172.18.0.3... telnet: Unable to connect to remote host: Connection refused
-
Kerolos William about 5 yearsare you using publish or expose for the docker ports you can check the following URL for more help nickjanetakis.com/blog/…
-
Radaeld about 5 yearsexpose since its the same network, testing inside the nginx container