Bad Gateway error

Hello,
I am configuring traefik to access my api in https. I have the impression that it works since I don't see any errors in the logs and I can access my whoami in https too. But every time I use my front-end url (https://dspace.localhost), I get a Bad Gateway error.
here are the contents of my traefik.yml file:

version: "3.9"

services:

  traefik:
    image: "traefik:v2.9.6"
    container_name: "traefik"
    command:
     
      - "--entrypoints.http.address=:80"
      - "--entrypoints.https.address=:443"
  
      - "--entrypoints.postgres.address=:5432"
      - "--api.insecure=true"
      - "--api.dashboard=true"
      
   
      - "--providers.docker=true"
      - "--providers.docker.swarmmode=true"
      - "--providers.docker.network=traefik-net"
      - "--providers.docker.exposedbydefault=false"
      - "--providers.file.filename=/configuration/certificate.yml"
      - "--providers.file.watch=true"
      
    ports:
      - "80:80"
      - "8888:8080"
      - "443:443"
      
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - "/C/opt/Savoirs_udes_project/DSpace7/volumes/configuration/:/configuration/"

  whoami:
    image: "traefik/whoami"

    deploy:
      labels:
        - "traefik.enable=true"
        - "traefik.http.routers.whoami.rule=Host(`whoami.localhost`)"
        - "traefik.http.routers.whoami.entrypoints=https"
        - "traefik.http.services.whoami.loadbalancer.server.port=80"
        - "traefik.http.routers.whoami.tls=true"

    networks:
      - traefik-net

networks:
  traefik-net:
    driver: overlay
    external: true
  dspace:
    driver: overlay
    external: true

certificate.yml:

tls:
  certificates:
    certFile = "/C/opt/Savoirs_udes_project/DSpace7/volumes/tls/local-cert.crt"
    keyFile = "/C/opt/Savoirs_udes_project/dSpace7/volumes/tls/local-key.key"


my_front-end.yml:

version: '3.9'
networks:
  dspace:
    driver: overlay
    external: true
  traefik-net:
    driver: overlay
    external: true
 
services:
  dspace-angular:
    environment:
      DSPACE_UI_SSL: 'true'
      DSPACE_UI_HOST: dspace.localhost
      DSPACE_UI_PORT: '4000'
      DSPACE_UI_NAMESPACE: /
      DSPACE_REST_SSL: 'true'
      DSPACE_REST_HOST: dspace-api.localhost
      DSPACE_REST_PORT: 443
      DSPACE_REST_NAMESPACE: /server
      NODE_OPTIONS: "--max-old-space-size=5120"

    image: thir2608/savoirs_front:latest
    build:
      context: ..
      dockerfile: Dockerfile
    networks:
      - dspace
      - traefik-net
    deploy:
      labels:
          - "traefik.enable=true"        
          - "traefik.http.routers.dspace-angular.entrypoints=https"      
          - "traefik.http.routers.dspace-angular.rule=Host(`dspace.localhost`)"             
          - "traefik.http.routers.dspace-angular.service=dspace-angular"
          - "traefik.http.services.dspace-angular.loadbalancer.server.port=4000"
          - "traefik.http.routers.dspace-angular.tls=true"

Thanks for your help.

The usual reason for "bad gateway" is the use of multiple networks, but you do define the one to use.

Two things I noticed:

  1. This feels strange: image and build at the same time
  1. This feels strange: driver and overlay at the same time

Thank you for your reply.
You're right about me using image and build in my docker-compose, in fact I was inspired by an existing docker-compose file.
For the network, I use traefik-net and I removed external:true but the error still persists.
What's strange is that my front-end and back-end have almost the same tls configuration, yet I can access the api in https.

You need to use a common Docker network. By itself compose creates an isolated network per file.

So you either need to create one manually in CLI and use external in both compose files or you create it in one compose file with attachable: true and name: and in the other one use external: true.

Yes, I saw that my service was connecting to a different network than traefik. So I manually created my network.
Thanks for your help.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.