Home > Blockchain >  NGINX and SPRINGBOOT in DOCKER container GOT 502 Bad Gateway
NGINX and SPRINGBOOT in DOCKER container GOT 502 Bad Gateway

Time:02-21

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

enter image description here

I cannot figure it out and need help.

CodePudding user response:

111: Connection refused) while connecting to upstream

is saying Nginx can't connect to the upstream server.

Your

proxy_pass http://heya;

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 be heya.

If the Java application is running on port 8080 inside the same container, talking the HTTP protocol, the correct proxy_pass would be

proxy_pass http://localhost:8080;

(since localhost in the container's view is the container itself).

CodePudding user response:

I finally got the answer!!

I ran nginx container and webapp container using host network mode, and it worked.

  • Related