0

I have these following container running on a server:

CONTAINER ID   IMAGE                           COMMAND                  CREATED         STATUS                 PORTS                                                            NAMES
c21c339e1299   gitlabanalyzer_frontend         "nginx -g 'daemon of…"   3 minutes ago   Up 3 minutes           0.0.0.0:8181->80/tcp                                             gitanalyzer-frontend
b3863853402c   gitlabanalyzer_backend:latest   "java -jar app.jar"      3 minutes ago   Up 3 minutes           0.0.0.0:8080->8080/tcp                                           gitanalyzer-backend
724c2cf79b67   gitlab/gitlab-ee:13.8.0-ee.0    "/assets/wrapper"        5 weeks ago     Up 5 weeks (healthy)   0.0.0.0:22->22/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:8282->80/tcp   gitlab_server_container_gitlab_1

I used nginx for reverse proxy (not a container), the content of /etc/nginx/conf.d/default.conf is:

server {
  listen        80;
  server_name   XXX;

  location / {
    proxy_pass  http://localhost:8181;
  }

  location /gitlab {
    proxy_pass  http://localhost:8282;
  }
}

So the frontend send API requests to the backend and the backend in turn, makes API requests to the gitlab server. All 3 containers are on the same machine. However, I keep getting: java.net.ConnectException: Connection refused (Connection refused) when the backend trying to connect to the gitlab server.

When I run a the backend from a different machine, I can connect the gitlab server on the server just fine, however, I got connection error when I try to run everything on the server.

Please help me out with how to solve this.

Monica.J
  • 27
  • 1
  • 6

1 Answers1

0

If they are on the same network in docker, then your default.conf file should be changed like this:

server {
  listen        80;
  server_name   XXX;

  location / {
    proxy_pass  http://gitanalyzer-frontend:8181;
  }

  location /gitlab {
    proxy_pass  http://gitlab_server_container_gitlab_1:8282;
  }
}

Else, you should put them in a same network.

Saeed
  • 3,255
  • 4
  • 17
  • 36
  • I've put them on the same network and modified the `default.conf` accordingly, but I got this error: `nginx: [emerg] host not found in upstream "gitanalyzer-frontend" in /etc/nginx/conf.d/default.conf:6`, just to clarify my nginx does not run in a container. – Monica.J Apr 01 '21 at 05:13
  • As said at https://stackoverflow.com/questions/42720618/docker-nginx-stopped-emerg-11-host-not-found-in-upstream, could you add a `resolver`? Also change `proxy_pass` values according to your container names if what I wrote is incorrect. – Saeed Apr 01 '21 at 10:15