504 Gateway Timeout

Hi, I migrate my Traefik v1 to v2. I have two react apps and one node API. My react apps are working but when I try to call my API I got a 504 Gateway Timeout.

This is my docker-file configuration:

services:
  traefik:
    image: traefik:v2.0
    container_name: traefik
    ports:
      - "80:80"
      - "443:443"
    command:
      - "--log.level=DEBUG"
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.websecure.address=:443"
      - "--certificatesresolvers.m4gie.acme.httpchallenge=true"
      - "--certificatesresolvers.m4gie.acme.httpchallenge.entrypoint=web"
      - "--certificatesresolvers.m4gie.acme.email=contact@m4gie.com"
      - "--certificatesresolvers.m4gie.acme.storage=/letsencrypt/acme.json"
      - "--certificatesResolvers.m4gie.acme.tlsChallenge=true"
      - "--certificatesresolvers.serv-hytale.acme.httpchallenge=true"
      - "--certificatesresolvers.serv-hytale.acme.httpchallenge.entrypoint=web"
      - "--certificatesresolvers.serv-hytale.acme.email=contact@m4gie.com"
      - "--certificatesresolvers.serv-hytale.acme.storage=/letsencrypt/acme.json"
      - "--certificatesResolvers.serv-hytale.acme.tlsChallenge=true"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - "./letsencrypt:/letsencrypt"

  api:
    image: api:latest
    container_name: api
    environment:
      ENV_SILENT: "true"
      HOST: "127.0.0.1"
      PORT: "3333"
      APP_URL: "http://127.0.0.1:3333"
      APP_KEY: "*******"
      NODE_ENV: "production"
      DB_CONNECTION: "pg"
      DB_HOST: "database"
      DB_PORT: "5432"
      DB_USER: "****"
      DB_PASSWORD: "****"
      DB_DATABASE: "****"
      MAIL_CONNECTION: "smtp"
      SMTP_HOST: "****"
      MAIL_USERNAME: "****"
      MAIL_PASSWORD: "****"
    labels:
      - "traefik.enable=true"
      - "traefik.http.middlewares.api-hytale-https.redirectscheme.scheme=https"
      - "traefik.http.routers.api-hytale-http.entrypoints=web"
      - "traefik.http.routers.api-hytale-http.rule=Host(`api.serv-hytale.fr`)"
      - "traefik.http.routers.api-hytale-http.middlewares=api-hytale-https@docker"
      - "traefik.http.routers.api-hytale.rule=Host(`api.serv-hytale.fr`)"
      - "traefik.http.routers.api-hytale.entrypoints=websecure"
      - "traefik.http.routers.api-hytale.tls=true"
      - "traefik.http.routers.api-hytale.tls.certresolver=serv-hytale"
    restart: on-failure
    depends_on:
      - database
      - traefik
    networks:
      - database
    read_only: false

Thanks !

Hello,

could you can try something like that:

services:
  traefik:
    image: traefik:v2.0
    container_name: traefik
    ports:
      - "80:80"
      - "443:443"
      - "8080:8080"
    command:
      - "--log.level=DEBUG"
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.websecure.address=:443"
      - "--certificatesresolvers.le.acme.email=contact@m4gie.com"
      - "--certificatesresolvers.le.acme.storage=/letsencrypt/acme.json"
      - "--certificatesResolvers.le.acme.tlsChallenge=true"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - "./letsencrypt:/letsencrypt"

  api:
    image: api:latest
    container_name: api
    environment:
      ENV_SILENT: "true"
      HOST: "127.0.0.1"
      PORT: "3333"
      APP_URL: "http://127.0.0.1:3333"
      APP_KEY: "*******"
      NODE_ENV: "production"
      DB_CONNECTION: "pg"
      DB_HOST: "database"
      DB_PORT: "5432"
      DB_USER: "****"
      DB_PASSWORD: "****"
      DB_DATABASE: "****"
      MAIL_CONNECTION: "smtp"
      SMTP_HOST: "****"
      MAIL_USERNAME: "****"
      MAIL_PASSWORD: "****"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.api-hytale-http.entrypoints=web"
      - "traefik.http.routers.api-hytale-http.rule=Host(`api.serv-hytale.fr`)"
      - "traefik.http.routers.api-hytale-http.middlewares=api-hytale-https@docker"

      - "traefik.http.middlewares.api-hytale-https.redirectscheme.scheme=https"

      - "traefik.http.routers.api-hytale.rule=Host(`api.serv-hytale.fr`)"
      - "traefik.http.routers.api-hytale.entrypoints=websecure"
      - "traefik.http.routers.api-hytale.tls.certresolver=le"

      - "traefik.http.services.api-hytale.loadbalancer.server.port=3333"
    restart: on-failure
    depends_on:
      - database
      - traefik
    networks:
      - database
    read_only: false

I'm still having the same error, that's my traefik logs but I didn't found anything interesting.

My new Docker compose configuration:

services:
  traefik:
    image: traefik:v2.0
    container_name: traefik
    ports:
      - "80:80"
      - "443:443"
      - "8080:8080"
    command:
      - "--log.level=DEBUG"
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.websecure.address=:443"
      - "--certificatesresolvers.le.acme.email=contact@m4gie.com"
      - "--certificatesresolvers.le.acme.storage=/letsencrypt/acme.json"
      - "--certificatesResolvers.le.acme.tlsChallenge=true"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - "./letsencrypt:/letsencrypt"


  api_hytale:
    image: api_hytale:latest
    container_name: api_hytale
    environment:
     ...
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.api-hytale-http.entrypoints=web"
      - "traefik.http.routers.api-hytale-http.rule=Host(`api.serv-hytale.fr`)"
      - "traefik.http.routers.api-hytale-http.middlewares=api-hytale-https@docker"

      - "traefik.http.middlewares.api-hytale-https.redirectscheme.scheme=https"

      - "traefik.http.routers.api-hytale.rule=Host(`api.serv-hytale.fr`)"
      - "traefik.http.routers.api-hytale.entrypoints=websecure"
      - "traefik.http.routers.api-hytale.tls.certresolver=le"
      
      - "traefik.http.services.api-hytale.loadbalancer.server.port=3333"
    restart: on-failure
    depends_on:
      - database
      - traefik
    networks:
      - database
    read_only: false


networks:
  database:
   external: false

I change my configuration to use networks and now I have a 502 Bad Gateway

My new configuration:

  traefik:
    image: traefik:v2.0
    container_name: traefik
    ports:
      - "80:80"
      - "443:443"
      - "8080:8080"
    command:
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.websecure.address=:443"
      - "--certificatesresolvers.le.acme.email=contact@m4gie.com"
      - "--certificatesresolvers.le.acme.storage=/letsencrypt/acme.json"
      - "--certificatesResolvers.le.acme.tlsChallenge=true"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - "./letsencrypt:/letsencrypt"
    networks:
      - web


  api_hytale:
    image: api_hytale:latest
    container_name: api_hytale
    environment:
      ...
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.api-hytale-http.entrypoints=web"
      - "traefik.http.routers.api-hytale-http.rule=Host(`api.serv-hytale.fr`)"
      - "traefik.http.routers.api-hytale-http.middlewares=api-hytale-https@docker"
      - "traefik.http.middlewares.api-hytale-https.redirectscheme.scheme=https"
      - "traefik.http.routers.api-hytale.rule=Host(`api.serv-hytale.fr`)"
      - "traefik.http.routers.api-hytale.entrypoints=websecure"
      - "traefik.http.routers.api-hytale.tls.certresolver=le"
      - "traefik.http.services.api-hytale.loadbalancer.server.port=3333"
    restart: on-failure
    depends_on:
      - database
      - traefik
    read_only: false
    networks:
      - web


volumes:
  database:

networks:
  web:
    external: true

Solved :partying_face:

My 504 error was fixed, it was because my networks were not setup. To fix my 502 error, I changed my API host HOST: "127.0.0.7" to HOST: "0.0.0.0"