首页 > 解决方案 > 子域有效,但域不在 Traefik 路由器规则中

问题描述

我有一个在开发中使用的工作 traefik 文件配置。

使用下面的配置,当我 docker-compose up可以访问主机时,api.contacts.localhost但是当我尝试访问contacts.localhost哪个为反应应用程序提供服务时,它没有,它会自动将其方案更改为https

  backend:
    build:
      context: "./api"
      target: dev
    container_name: backend
    environment:
      - APP_PORT
      - APP_HOSTNAME
      - DB_USER
      - DB_PASSWORD
      - DB_HOST
    env_file: ".env"
    expose:
      - 4000
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=traefik"
      - "traefik.http.routers.backend.rule=Host(`api.contacts.localhost`)"
      - "traefik.port=80"
    volumes:
      - "./api:/app"
    depends_on:
      - database

  client:
    build:
      context: "./client"
      target: dev
    container_name: client
    ports:
      - "3000:3000"
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=traefik"
      - "traefik.http.routers.client.rule=Host(`contacts.localhost`)"
      - "traefik.port=80"
    depends_on:
      - backend
    volumes:
      - "./client:/app"

如果我将规则client从更改contacts.localhostclient.contacts.localhost

client:
    ...
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=traefik"
      - "traefik.http.routers.client.rule=Host(`client.contacts.localhost`)"
      - "traefik.port=80"

我现在可以访问我的反应应用程序。

有没有办法在不需要子域的情况下为我的反应应用程序提供服务?

标签: dockerdocker-composetraefik

解决方案


推荐阅读