Can't expose my NestJS API on port 80

Hello,
I'm trying to get my NestJS API to get exposed on http://sub.mydomain.tld/api (and previously done it with success through Apache). The docker container exposes the api on port 3000. I want to access it on port 80 (later on 443, one problem at a time).
It currently works when accessing on http://sub.mydomain.tld:3000.

As I want to use Traefik for routing over my docker, I need to remove my Apache listening on 80 port for proxypass.

Here is what I tried in my docker-compose file :

services:
  reverse-proxy:
    # The official v3 Traefik docker image
    image: traefik:v3.3
    # Enables the web UI and tells Traefik to listen to docker
    command: --providers.docker --providers.docker.useBindPortIP=true --api.insecure=true
    ports:
      # The HTTP port
      - "80:80"
      # The Web UI (enabled by --api.insecure=true)
      - "8080:8080"
    volumes:
      # So that Traefik can listen to the Docker events
      - /var/run/docker.sock:/var/run/docker.sock

  my-api-gateway:
    container_name: 'my-api-gateway'
    image: myorg/my-api-gateway:latest
    restart: always
    environment:
      REDIS_HOST: gateway-redis
      DB_HOST: gateway-postgres
    env_file:
      - ./my-api-gateway.env
    ports:
      - ${SERVER_PORT}:${SERVER_PORT}
    networks:
      - nestjs-net
    depends_on:
      gateway-redis:
        condition: service_healthy
      gateway-postgres:
        condition: service_healthy
    labels:
      - "traefik.enable=true"
      - "traefik.port=3000"
      - "traefik.http.services.my-api-gateway.loadbalancer.server.port=80"
      - "traefik.http.routers.my-api-gateway.entrypoints=http"
      - "traefik.http.routers.my-api-gateway.rule=Host(`sub.mydomain.tld`) && PathPrefix(`/api`)"
      - "traefik.http.routers.my-api-gateway.middlewares=strip-api"
      - "traefik.http.middlewares.strip-api.stripprefix.prefixes=/api"

  gateway-redis:
    container_name: 'gateway-redis'
    image: bitnami/redis:7.4
    restart: always
    ports:
      - ${REDIS_PORT}:${REDIS_PORT}
    environment:
      REDIS_PASSWORD: ${REDIS_PASSWORD}
      REDIS_PORT_NUMBER: ${REDIS_PORT}
      REDIS_DB: ${REDIS_DB}
      REDIS_IO_THREADS: 4
      REDIS_IO_THREADS_DO_READS: "yes"
      REDIS_DISABLE_COMMANDS: FLUSHDB,FLUSHALL
    healthcheck:
      test: ['CMD', 'redis-cli', '--raw', 'incr', 'ping']
      interval: 5s
      timeout: 5s
      retries: 5
    volumes:
      - gateway-redis-data:/bitnami/redis/data
    networks:
      - nestjs-net

  gateway-postgres:
    container_name: 'gateway-postgres'
    image: postgres
    restart: always
    environment:
      POSTGRES_PORT_NUMBER: ${DB_PORT}
      POSTGRES_USERNAME: ${DB_USER}
      PGUSER: ${DB_USER}
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_DB: ${DB_NAME}
      POSTGRES_TIMEZONE: 'Europe/Paris'
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready']
      interval: 5s
      timeout: 5s
      retries: 5
    ports:
      - ${DB_PORT}:${DB_PORT}
    volumes:
      - gateway-postgres-data:/postgres
    networks:
      - nestjs-net

volumes:
  gateway-redis-data:
    driver: local
  gateway-postgres-data:
    driver: local

networks:
  nestjs-net:
    driver: bridge

Can you please help me ?

You have no entrypoints declared. Check simple Traefik example.

Ok, but the http entry point seems to work fine there :


Do I need to create another one on the same port ?

Not sure where that entrypoint comes from. You also use a traefik.yml static config file?

You also did not state what your problem really is, any error messages?

Hello, no I don't use any other configuration, that's why I thought it was a default entrypoint I could use.

I created a web entrypoint on the same port, and all the other services that were on the "default" http entrypoint automatically used the new web entrypoint an it's working now.

What I don't understand is then, why, for another independant docker in the same docker-compose file, it worked without any other configuration, on the "default" http entrypoint :man_shrugging:

Thank you for your help, and sorry if I wasted your time.

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