Can't run multiple sites

Hi guys,

When I start just one of my services, it shows up on the Traefik dashboard under routers and services, and I am able to access the site. When I start the other, both show up under services, but neither shows up under routers, and I am not able to access either site. All config is below. Anyone have any ideas?

## traefik/docker-compose.yml
version: '3.2'

services:
  traefik:
    # The official v2.0 Traefik docker image
    image: traefik:v2.0
    ports:
      # The HTTP port
      - "80:80"
      # The HTTPS port
      - "443:443"
    volumes:
      # So that Traefik can listen to the Docker events
      - /var/run/docker.sock:/var/run/docker.sock
      - /var/docker/traefik/traefik.yml:/etc/traefik/traefik.yml:ro
      - /var/docker/traefik/shared-config.yml:/etc/traefik/shared-config.yml:ro
      - certs:/etc/traefik/acme
    labels:
      # traefik dashboard
      - "traefik.enable=true"
      - "traefik.http.routers.api.rule=Host(`monitor2.example.com.io`)"
      - "traefik.http.routers.api.service=api@internal"
      - "traefik.http.routers.api.entrypoints=http"
      - "traefik.http.routers.api-secure.rule=Host(`monitor2.example.com.io`)"
      - "traefik.http.routers.api-secure.tls=true"
      - "traefik.http.routers.api-secure.entrypoints=https"
      - "traefik.http.routers.api-secure.tls.certresolver=letsencrypt"
      - "traefik.http.routers.api-secure.middlewares=admin@file"
      # middleware https redirect
      - "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
      # global redirect to https
      - "traefik.http.routers.redirs.rule=hostregexp(`{host:.+}`)"
      - "traefik.http.routers.redirs.entrypoints=http"
      - "traefik.http.routers.redirs.middlewares=redirect-to-https"
    networks:
      - reverse-proxy

volumes:
  certs:

networks:
  reverse-proxy:
    external:
      name: reverse-proxy
## traefik/traefik.yml

log:
  level: DEBUG

# Docker configuration backend
providers:
  docker:
    defaultRule: "Host(`{{ trimPrefix `/` .Name }}.example.com`)"
    exposedByDefault: false
  file:
    filename: /etc/traefik/shared-config.yml
    watch: true

# API and dashboard configuration
api:
  dashboard: true
  debug: true

entryPoints:
  http:
    address: ":80"
  https:
    address: ":443"

certificatesResolvers:
  letsencrypt:
    acme:
      caServer: "https://acme-staging-v02.api.letsencrypt.org/directory"
      email: scott@example.com
      storage: /etc/traefik/acme/acme.json
      httpChallenge:
        # used during the challenge
        entryPoint: http
## traefik/shared-config.yml
http:
  middlewares:
    admin:
      basicAuth:
        users:
          - scott:scrubbed
    marketing:
      basicAuth:
        users:
          - marketing:scrubbed
## landing/docker-compose.yml
version: '3.2'

services:
  php-fpm:
    image: docker.example.com/landing/php-fpm:develop
    environment:
      MAILCHIMP_API_KEY: 'scrubbed'
      MAILCHIMP_LIST_ID: 'scrubbed'
    networks:
      - backend
      
  nginx:
    depends_on:
      - php-fpm
    image: docker.example.com/landing/nginx:develop
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.nginx.rule=Host(`landing-dev.example.com`)"
      - "traefik.http.routers.nginx.tls=true"
      - "traefik.http.routers.nginx.entrypoints=https"
      - "traefik.http.routers.nginx.tls.certresolver=letsencrypt"
      - "traefik.http.routers.nginx.middlewares=marketing@file"
    networks:
      - backend
      - reverse-proxy

networks:
  backend:
  reverse-proxy:
    external:
      name: reverse-proxy
## statamic/docker-compose.yml
version: '3.2'

services:
  php-fpm:
    image: docker.example.com/site/php-fpm:latest
    environment:
      APP_ENV: development
      APP_URL: https://sandbox.example.com
      HTTPS: 'on'
    volumes:
      - statamic-local:/var/www/local
      - statamic-site:/var/www/site
    networks:
      - backend
  nginx:
    depends_on:
      - php-fpm
    image: docker.example.com/site/nginx:latest
    # ports:
    #   - "8000:80"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.nginx.rule=Host(`sandbox.example.com`)"
      - "traefik.http.routers.nginx.tls=true"
      - "traefik.http.routers.nginx.entrypoints=https"
      - "traefik.http.routers.nginx.tls.certresolver=letsencrypt"
      - "traefik.http.routers.nginx.middlewares=marketing@file"
    networks:
      - backend
      - reverse-proxy

volumes:
  statamic-local:
  statamic-site:

networks:
  backend:
  reverse-proxy:
    external:
      name: reverse-proxy

Your services in traefik.http.routers.{service}. should be unique, referring the doc
Here you are defining 2 same services names with two different services.
See https://github.com/Darkweak/WorkshopContainous/tree/master/factorization-p2 to view one way to fix that (define env var which take folder name combined to service name)

1 Like