I deployed my springboot project in docker container opening port 8080 as well as an nginx server opening port 80
enter image description here
When I use
curl http://localhost:8080/heya/index
it returns normally
But when I use
curl http://localhost/heya/index
hoping I can reach from nginx proxy,it failed. And I checked the log, it says
*24#24: 11 connect() failed (111: Connection refused) while connecting to upstream, client: 172.17.0.1, server: , request: "GET /heya/index HTTP/1.1", upstream: "http://127.0.0.1:8080/heya/index", host: "localhost"
Here is my nginx.conf
I cannot figure it out and need help.
2
Answers
I finally got the answer!!
I ran nginx container and webapp container using host network mode, and it worked.
is saying Nginx can’t connect to the upstream server.
Your
is telling Nginx that the upstream is talking the HTTP protocol [on the default port 80] on the hostname
heya
. Unless you’re running multiple containers in the same Compose network, it’s unlikely that the hostname would beheya
.If the Java application is running on port 8080 inside the same container, talking the HTTP protocol, the correct
proxy_pass
would be(since
localhost
in the container’s view is the container itself).