Traefik routing to two different domains

Hi,

I am new to Traefik but want to replace my current Nginx (jwilder).
I have installed Traefik v2 in docker with the following docker-compose.yml with Lets Encrypt

version: '3'

services:
  traefik:
    image: traefik:v2.2
    restart: always
    ports:
      - 80:80
      - 443:443
      - 8080:8080
    networks:
      - web
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /data/disk1/traefik/traefik.yml:/traefik.yml
      - /data/disk1/traefik/acme.json:/acme.json
    container_name: traefik
networks:
  web:
    external: true

I have setup Confluence on one domain and docker-compose.yml

version: "3"

services:
  confluence:
    container_name: confluence
    image: atlassian/confluence-server:7.6.2
    volumes:
      - /data/disk1/atlassian/application-data/confluence:/var/atlassian/application-data/confluence
    ports:
      - "8090:8090"
    external_links:
      - postgres:postgres
    environment:
      - CATALINA_CONNECTOR_PROXYNAME=confluence.mydomain.com
      - CATALINA_CONNECTOR_PROXYPORT=443
      - CATALINA_CONNECTOR_SCHEME=https
      - CATALINA_CONNECTOR_SECURE=true
    labels:
      - traefik.enable=true
      - traefik.http.routers.confluence.rule=Host(`confluence.mydomain.com`)
      - traefik.http.routers.confluence.tls=true
      - traefik.http.routers.confluence.tls.certresolver=le
      - traefik.http.routers.confluence.service=confluence
      - traefik.http.services.confluence.loadbalancer.server.port=8090
    networks:
      - web
    restart: always
networks:
  web:
    external:
      name: web

It works fine and I also have NextCloud working on the same TLD.

But when trying to spin up a simple Nginx website on another domain is doesn't work.
The docker-compose.yml

version: "3"

services:
  another-domain-web:
    container_name: another-domain-web
    image: nginx:latest
    volumes:
      - /data/disk1/another-domain/www/:/usr/share/nginx/html:ro
      - /data/disk1/another-domain/conf/nginx.conf:/etc/nginx/nginx.conf:ro
    ports:
      - 9999:80
    labels:
      - traefik.enable=true
      - traefik.http.routers.another-domain-web.rule=Host(`another-domain.com`)
      - traefik.http.routers.another-domain-web.tls=true
      - traefik.http.routers.another-domain-web.tls.certresolver=le
      - traefik.http.routers.another-domain-web.service=another-domain-web
      - traefik.http.services.another-domain-web.loadbalancer.server.port=9999
    networks:
      - web
    restart: always
networks:
  web:
    external:
      name: web

In Traefik it looks good I think (see screenshots below)


But when requesting http://another-domain.com/ I get redirected to https://another-domain.com/ and getting "Bad Gateway"

I see in acme that certificate is received and the browser tells it is valid.

Any hints to resolve this?

This should be the port inside the container. In this case 80. The port you have in the ports section is not used by traefik(I don't expose a port like this at all once is a service is working behind traefik).

1 Like

Aha, thanks @cakiwi works just fine.
That also explains why my Nextcloud + Collabora works :slight_smile:
So if you don't need to access the container directly (without Traefik) there is no need to expose ports.

For reference Nextcloud + Collabora docker-compose.yml

version: '2'
services:
  web:
    image: nginx
    container_name: nextcloud_webserver
    volumes:
      - /data/disk1/nginx-nextcloud/nginx.conf:/etc/nginx/nginx.conf:ro
    links:
      - app
      - collabora
    volumes_from:
      - app
    labels:
      - traefik.enable=true
      - traefik.http.routers.nextcloud.rule=Host(`nextcloud.domain.com`)
      - traefik.http.routers.nextcloud.tls=true
      - traefik.http.routers.nextcloud.tls.certresolver=le
      - traefik.http.routers.nextcloud.service=nextcloud
      - traefik.http.services.nextcloud.loadbalancer.server.port=80
    networks:
      - web
    restart: always

  app:
    image: nextcloud:19.0.1-fpm
    container_name: nextcloud_fpm
    volumes:
      - /data/disk1/nextcloud/apps:/var/www/html/apps
      - /data/disk1/nextcloud/config:/var/www/html/config
      - /data/disk1/nextcloud/data:/var/www/html/data
    environment:
      - POSTGRES_DB=nextcloud
      - POSTGRES_USER=nextcloud
      - POSTGRES_PASSWORD=***********
      - POSTGRES_HOST=192.168.1.11
    networks:
      - web
    restart: always

  collabora:
    image: collabora/code:4.2.6.2
    container_name: nextcloud_collabora
    cap_add:
      - MKNOD
    environment:
      - domain=nextcloud.domain.com
    networks:
      - web
    restart: always

networks:
  web:
    external:
      name: web