Cannot call DotNet API endpoints from Traefik

I'm new to Traefik, i was able to successfuly host an angular server and use Traefik to assign a domain to it.

Now i'm trying to use Traefik to call my dotnet core api, i've been stuck in this for two days now and can't seem to do it correctly, i am not able to call my endpoints through Traefik, but if i expose my api port directly i can call the IP of the server with the port and execute GET and POST requests.

If somebody could help me figure this out i would very thankful, is this even possible what i am trying to accomplish?

traefik.yaml

global:
  checkNewVersion: false
  sendAnonymousUsage: false

# -- (Optional) Change Log Level and Format here...
#     - loglevels [DEBUG, INFO, WARNING, ERROR, CRITICAL]
#     - format [common, json, logfmt]
log:
 level: DEBUG
 format: common
 filePath: /var/log/traefik/traefik.log

# -- (Optional) Enable Accesslog and change Format here...
#     - format [common, json, logfmt]
accesslog:
  format: common
  filePath: /var/log/traefik/access.log

# -- (Optional) Enable API and Dashboard here, don't do in production
api:
  dashboard: true
  insecure: true

# -- Change EntryPoints here...
entryPoints:
  web:
    address: :80
    # -- (Optional) Redirect all HTTP to HTTPS
    http:
      redirections:
        entryPoint:
          to: websecure
          scheme: https
  websecure:
    address: :443
  # -- (Optional) Add custom Entrypoint
  # custom:
  #   address: :8080

# -- Configure your CertificateResolver here...
certificatesResolvers:
  staging:
    acme:
      email: example@example.com
      storage: /ssl-certs/acme.json
      caServer: "https://acme-staging-v02.api.letsencrypt.org/directory"
      #-- (Optional) Remove this section, when using DNS Challenge
      httpChallenge:
        entryPoint: web
      #-- (Optional) Configure DNS Challenge
      # dnsChallenge:
      #   provider: your-resolver (e.g. cloudflare)
      #   resolvers:
      #     - "1.1.1.1:53"
      #     - "8.8.8.8:53"
  production:
    acme:
      email: example@example.com
      storage: /ssl-certs/acme.json
      caServer: "https://acme-v02.api.letsencrypt.org/directory"
      #-- (Optional) Remove this section, when using DNS Challenge
      httpChallenge:
        entryPoint: web
      #-- (Optional) Configure DNS Challenge
      # dnsChallenge:
      #   provider: your-resolver (e.g. cloudflare)
      #   resolvers:
      #     - "1.1.1.1:53"
      #     - "8.8.8.8:53"

# -- (Optional) Disable TLS Cert verification check
# serversTransport:
#   insecureSkipVerify: true

# -- (Optional) Overwrite Default Certificates
# tls:
#   stores:
#     default:
#       defaultCertificate:
#         certFile: /etc/traefik/certs/cert.pem
#         keyFile: /etc/traefik/certs/cert-key.pem
# -- (Optional) Disable TLS version 1.0 and 1.1
#   options:
#     default:
#       minVersion: VersionTLS12

providers:
  docker:
    # -- (Optional) Enable this, if you want to expose all containers automatically
    exposedByDefault: false
  file:
    directory: /etc/traefik
    watch: true

docker-compose.yaml

version: '3.8'

networks:
  db_network:  
  keycloak_network:
  traefik-network:
  vpn_network:
    ipam:
      config:
      - subnet: 192.168.123.0/24

services:
  api:
    image: api:latest
    container_name: api
    restart: unless-stopped
    environment:
      ASPNETCORE_URLS: http://*:5000/
      ASPNETCORE_ENVIRONMENT: DebianLocal
      DB_HOST: db-container
      DB_PORT: 5432
      DB_NAME: db
      DB_USER: admin
      DB_PASSWORD: admin
    ports:
      - 5000:5000
    labels:
      traefik.enable: true
      traefik.http.routers.api.entrypoints: websecure
      traefik.http.routers.api.rule: Host(`example-api.xyz`)
      traefik.http.services.api.loadbalancer.server.port: 5000
      traefik.http.routers.api.tls: true
      traefik.http.routers.api.tls.certresolver: staging
    volumes:
      - ./config/api/ssl-certs:/https
    networks:
      keycloak_network:
      db_network:
      traefik-network:

  angular:
    image: angular:latest
    container_name: angular
    restart: unless-stopped
    volumes:
      - ./config/angular/nginx/nginx.conf:/etc/nginx/nginx.conf
    labels:
      traefik.enable: true
      traefik.http.routers.angular.entrypoints: websecure
      traefik.http.routers.angular.rule: Host(`example.xyz`)
      traefik.http.routers.angular.tls: true
      traefik.http.routers.angular.tls.certresolver: production
    networks:
      traefik-network:

  traefik:
    image: traefik:v2.11.0
    container_name: traefik
    ports:
      - 80:80
      - 443:443
      # -- (Optional) Enable Dashboard, don't do in production
      #- 8081:8080
    volumes:
      - ./config/traefik:/etc/traefik
      - ./config/traefik/ssl-certs:/ssl-certs
      - /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
      traefik-network:
      vpn_network:
        ipv4_address: 192.168.123.4
    restart: unless-stopped

If you need anything else to help figure this out just ask and i will provide. My goal is to be able to call the api with something like example-api.xyz/api/getUsers, is this possible with traefik?
With example-api.xyz being my domain

It would be helpful to see the error message, you can check browsers developer tools network tab.

It might be "gateway error", as your target service has multiple networks assigned, which Traefik has not. Set the Docker network to use (doc), but be aware that compose might prepend a network name with the project prefix. To avoid that, use name: for every network, see simple Traefik example.

wow man, that was amazing, it worked!

That explains why some hours ago it started working and then stopped and never worked again, i was very confused cause i didn't change anything and it stopped working all of a sudden, basically traefik was picking a random network i would have never found this out, thanks a lot man!

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