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 ?