Multidomain and pathprefix with two containers

Hello all. Could you help me with my trouble? I've been stuck with this for a few days and cant understand how to fix problem.
I have two containers with frontend and admin area.
Frontend needs to use multidomain for cities. Example: city1.${ROOT_DOMAIN}, city2.${ROOT_DOMAIN}, city3.${ROOT_DOMAIN}.
Admin area uses city1.domain.com/admin. Both containers deployed to the manager swarm node.
It works when I use one domain for frontend and admin area. But frontend gives 404 for admin area when I turn on multidomain configuration.
My last versions of compose files for services and config for traefik
services:
admin_area:
image: ${RELEASE_IMAGE}
hostname: admin_area
deploy:
placement:
constraints:
- node.role == manager
labels:
- traefik.enable=true
- traefik.docker.network=traefik-network
- traefik.http.services.admin_area.loadbalancer.server.port=8080
- "traefik.http.routers.admin_area.rule=Host(city1.${ROOT_DOMAIN}) && PathPrefix(/admin) || Host(city2.${ROOT_DOMAIN}) && PathPrefix(/admin) Host(city3.${ROOT_DOMAIN}) && PathPrefix(/admin)"
- "traefik.http.routers.admin_area.entrypoints=https"
- "traefik.http.routers.admin_area.tls=true"
- "traefik.http.routers.admin_area.tls.certresolver=letsencrypt"
networks:
- traefik-network

services:
front_main:
image: ${RELEASE_IMAGE}
hostname: front_main
expose:
- 3000
deploy:
placement:
constraints:
- node.role == manager
labels:
- "traefik.enable=true"
- "traefik.docker.network=traefik-network"
- "traefik.http.services.front_main.loadbalancer.server.port=3000"
- "traefik.http.routers.front_main.rule=Host(city1.${ROOT_DOMAIN}) || Host(city2.${ROOT_DOMAIN}) || Host(city3.${ROOT_DOMAIN})"
- "traefik.http.routers.front_main.entrypoints=https"
- "traefik.http.routers.front_main.tls=true"
- "traefik.http.routers.front_main.tls.certresolver=letsencrypt"
- "traefik.http.routers.front_main.tls.domains[0].main=city1.${ROOT_DOMAIN}"
- "traefik.http.routers.front_main.tls.domains[1].main=city2.${ROOT_DOMAIN}"
- "traefik.http.routers.front_main.tls.domains[2].main=city3.${ROOT_DOMAIN}"
networks:
- traefik-network

Traefik config.yaml
...
http:
routers:
http-catchall:
rule: "HostRegexp({subdomain:[a-z]+}.${ROOT_DOMAIN})"
entrypoints:
- http
middlewares:
- redirect-to-https
middelewares:
redirect-to-https:
redirectscheme:
scheme: https
permanent: false
...

Use 3 backticks before and after code/config to make it readable.

Readable configs

services:
  admin_area:
    image: ${RELEASE_IMAGE}
    hostname: admin_area
    deploy:
      placement:
        constraints:
          - node.role == manager
      labels:
        - traefik.enable=true
        - traefik.docker.network=traefik-network
        - traefik.http.services.admin_area.loadbalancer.server.port=8080
        - "traefik.http.routers.admin_area.rule=Host(`city1.${ROOT_DOMAIN}`) && PathPrefix(`/admin`) ||
 Host(`city2.${ROOT_DOMAIN}`) && PathPrefix(`/admin`) Host(`city3.${ROOT_DOMAIN}`) && PathPrefix(`/admin`)"
       - "traefik.http.routers.admin_area.entrypoints=https"
       - "traefik.http.routers.admin_area.tls=true"
       - "traefik.http.routers.admin_area.tls.certresolver=letsencrypt"
    networks:
       - traefik-network
services:
  front_main:
    image: ${RELEASE_IMAGE}
    hostname: front_main
    expose:
       - 3000
    deploy:
      placement:
        constraints:
          - node.role == manager
      labels:
        - "traefik.enable=true"
        - "traefik.docker.network=traefik-network"
        - "traefik.http.services.front_main.loadbalancer.server.port=3000"
        - "traefik.http.routers.front_main.rule=Host(city1.${ROOT_DOMAIN}) || Host(city2.${ROOT_DOMAIN}) || Host(city3.${ROOT_DOMAIN})"
        - "traefik.http.routers.front_main.entrypoints=https"
        - "traefik.http.routers.front_main.tls=true"
        - "traefik.http.routers.front_main.tls.certresolver=letsencrypt"
        - "traefik.http.routers.front_main.tls.domains[0].main=city1.${ROOT_DOMAIN}"
        - "traefik.http.routers.front_main.tls.domains[1].main=city2.${ROOT_DOMAIN}"
        - "traefik.http.routers.front_main.tls.domains[2].main=city3.${ROOT_DOMAIN}"
    networks:
      - traefik-network
http:
  routers:
    http-catchall:
      rule: "HostRegexp(`{subdomain:[a-z]+}.${ROOT_DOMAIN}`)"
      entrypoints:
      - http
      middlewares:
        - redirect-to-https
    middelewares:
      redirect-to-https:
        redirectscheme:
          scheme: https
          permanent: false

Oh yes, thank you. my bad. Added configs

Try using more parenthesis in rule:

( Host() && PathP() ) || (…)

You can probably simplify:

( Host() || Host() || Host() ) && PathPrefix(`/admin`)

Thank you very much. Thats worked!

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