Im trying to set a reverse_proxy with nginx
i'm using image docker of nginx and back-end servers that I'm trying to reach by the reverse_proxy are an application angular i did a dockerfile of that app and i have also a API as image i did docker file for it also
I created a docker compose but i after i run docker-compose up
it happens that only only the API (called folwable-ui) works but the application of angular give a response of 502 Bad Gateway nginx/1.23.0
here is my docker compose
services:
reverseproxy:
build:
context: .
dockerfile: nginx.Dockerfile
ports:
- "443:443"
- "80:80"
restart: always
volumes:
- ./nginx/conf/:/etc/nginx/conf.d/:ro
postgres:
depends_on:
- reverseproxy
build:
context: .
dockerfile: postgres.Dockerfile
environment:
- POSTGRES_USER=flowable
- POSTGRES_PASSWORD=flowable
- POSTGRES_DB=flowable
- POSTGRES_HOST_AUTH_METHOD=password
ports:
- "15432:5432"
restart: always
flowableui:
depends_on:
- postgres
build:
context: .
dockerfile: flowable.Dockerfile
environment:
- SPRING_DATASOURCE_DRIVER-CLASS-NAME=org.postgresql.Driver
- SPRING_DATASOURCE_URL=jdbc:postgresql://host.docker.internal:15432/flowable
- SPRING_DATASOURCE_USERNAME=flowable
- SPRING_DATASOURCE_PASSWORD=flowable
ports:
- "8080:8080"
restart: always
angularboite:
depends_on:
- flowableui
- reverseproxy
build:
context: ./BoiteATacheTemplate
dockerfile: Dockerfile
ports:
- 4200:4200
and here is my nginx.conf file :
events { worker_connections 1024; }
http {
sendfile on;
large_client_header_buffers 4 32k;
upstream service1 {
server flowableui:8080;
}
upstream service2 {
server angularboite:4200;
}
server {
listen 80;
server_name www.dzflow.com dzflow.com;
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 80;
server_name boiteatache;
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name www.dzflow.com dzflow.com;
ssl_certificate /etc/ssl/certs/dzflow.crt;
ssl_certificate_key /etc/ssl/private/dzflow.key;
location /flowable-ui {
proxy_pass http://service1/flowable-ui;
proxy_redirect off;
proxy_http_version 1.1;
proxy_cache_bypass $http_upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $server_name;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
log_not_found off;
}
location /boite {
proxy_pass http://service2/login;
proxy_redirect off;
proxy_http_version 1.1;
proxy_cache_bypass $http_upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $server_name;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
log_not_found off;
}
location = /favicon.ico {
return 204;
access_log off;
log_not_found off;
}
}
}
my Dockerfile of angular-app:
FROM node:latest as node
# Set the working directory
WORKDIR /app
# Add the source code to app
COPY . .
# Install all the dependencies
RUN npm install -f
# Expose port
EXPOSE 4200
ENTRYPOINT ["npm","start"]
nginx Dockerfile :
FROM nginx:latest
COPY nginx.conf /etc/nginx/nginx.conf
COPY dzflow.crt /etc/ssl/certs/dzflow.crt
COPY dzflow.key /etc/ssl/private/dzflow.key
and when i go to check the logs of the container of reverseproxy it gives me this :
2022/07/07 09:21:45 [error] 22#22: *2 connect() failed (111: Connection refused) while
connecting to upstream, client: 172.21.0.1, server: www.dzflow.com, request: "GET /boite
HTTP/1.1", upstream: "http://172.21.0.5:4200/login", host: "localhost"
172.21.0.1 - - [07/Jul/2022:09:21:45 +0000] "GET /boite HTTP/1.1" 502 559 "-"
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/103.0.0.0 Safari/537.36"
please can someone help