Environment setup
I have an application which is composed by some services:
- jenkins server
- nginx server with angular
- nginx server as a proxy
Those services are defined in the docker-compose
file:
version: '3'
services:
reverse:
container_name: reverse-proxy
build:
context: /app/mywallet/MyWalletFe/reverse-proxy
ports:
- "80:80"
networks:
- net
jenkins:
container_name: jenkins
image: jenkins/jenkins
volumes:
- "$PWD/jenkins_home:/var/jenkins_home"
- "/var/run/docker.sock:/var/run/docker.sock"
networks:
- net
angular:
container_name: mywallet_fe
build:
context: /app/mywallet/MyWalletFe
networks:
- net
networks:
net:
I defined the following configuration file for the reverse-proxy
:
upstream client {
# angular is the name of the service in docker-compose file
server angular:4200;
}
upstream jenkins {
server jenkins:8080;
}
server {
listen 80;
location / {
proxy_pass http://client;
}
location /jenkins {
proxy_pass http://jenkins;
}
}
Finally, here is the Dockerfile
for the reverse-proxy
service, which copies the configuration file in the nginx container:
FROM nginx
# override default files if present
COPY ./default.conf /etc/nginx/conf.d/default.conf
Goal
My goal is to access Jenkins with SERVER_IP/jenkins
Output
When I run the whole application and try to access to SERVER_IP/jenkins
, I get the following error in the reverse-proxy logs:
2020/04/15 21:44:55 [error] 6#6: *10 connect() failed (111: Connection refused) while connecting to upstream, client: MY_CLIENT_IP, server: , request: "GET /login?from=%2Fjenkins HTTP/1.1", upstream: "http://172.18.0.5:4200/login?from=%2Fjenkins", host: "SERVER_IP", referrer: "http://SERVER_IP/jenkins" MY_CLIENT_IP
[15/Apr/2020:21:44:55 +0000] "GET /favicon.ico HTTP/1.1" 502 559 "http://SERVER_IP/login?from=%2Fjenkins" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36" "-" 2020/04/15 21:44:55 [error] 6#6: *10 connect() failed (111: Connection refused) while connecting to upstream, client: MY_CLIENT_IP, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://172.18.0.5:4200/favicon.ico", host: "SERVER_IP", referrer: "http://SERVER_IP/login?from=%2Fjenkins"
where MY_CLIENT_IP
is my laptop IP and SERVER_IP
is the IP of the server where the application runs.
What's wrong in the configuration of the reverse proxy? If I expose the jenkins and angular services I can reach them, while through the proxy I can't.
Similar question, which doesn't help me (or I don't understand how would those help me)
- Docker nginx reverse proxy returns 502 bad gateway "connection refused while connecting to upstream"
- Connection refused while connection to upstream - Docker
- connect() failed (111: Connection refused) while connecting to upstream for nginx+php-fpm docker
- docker nginx connection refused while connecting to upstream