Docker中的Traefik:路径路由不起作用

时间:2020-03-17 15:17:59

标签: docker traefik

我正在尝试在Docker主机上的容器中设置traefik: 主机:myserver.some.domain Traefik:v2.1.3 Docker主机:v19.03.8

当我请求“ http://myserver.some.domain/traefik”时,我想查看仪表板,并且进一步的导航应该像请求第一个URL并登陆“ http://myserver.some.domain/traefik/dashboard/#/”一样反映在URL中。 我尝试了多种中间件:

  • 路径
  • PathPrefix
  • StripPrefix

到目前为止,PathPrefix听起来是最正确的选择,但是我得到“找不到404页”。 现在,我还公开了端口8080,因此可以交叉检查所做的更改(在http://myserver.some.domain:8080上有效)。稍后,我想隐藏端口8080,只让端口80上的路由完成工作。

我的docker-compose.yml看起来像这样:

version: "3"

services:
  traefik:
    image: traefik:2.1.3
    container_name: 'traefik'
    command:
      # Enable DEBUG log for issue resolving
      - "--log.level=DEBUG"
      # Enable dashboard
      - "--api.dashboard=true"
      # Enable debug information in api
      - "--api.debug=true"
      # Allow api access on unsecure http requests
      # Will be removed when SSL will be configured
      - "--api.insecure=true"
      # Default http port
      - "--entrypoints.web.address=:80"
      # Dashboard port
      - "--entrypoints.traefik.address=:8080"
      # Allow traefik to se other docker containers for dynamic routing
      - "--providers.docker.endpoint=unix:///var/run/docker.sock"
      # Hide containers without traefik configuration by default
      - "--providers.docker.exposedByDefault=false"
      # Use the container's configured network
      # All containers use network "proxy", type "bridge"
      - "--providers.docker.useBindportIP=false"
    labels:
      # Enable Traefik configuration for container
      traefik.enable: "true"
      # Use docker network "proxy"
      traefik.docker.network: "proxy"
      # Define http entrypoint
      traefik.http.routers.traefik.entrypoints: "web"
      # Proxy all requests which start with "/traefik"
      traefik.http.routers.traefik.rule: "PathPrefix(`/traefik`)"
#      # Proxy request on path "/traefik"
#      traefik.http.routers.traefik.rule: "Path(`/traefik`)"
      # Replace path prefix "/traefik" with "/"
      traefik.http.routers.traefik.middlewares: "traefik_replacepath"
      traefik.http.middlewares.traefik_replacepath.replacePath.path: "/"
#      # Strip path prefix "/traefik" and force slash "/"
#      traefik.http.routers.traefik.middlewares: "traefik_stripprefix"
#      traefik.http.middlewares.traefik_stripprefix.stripprefix.prefices: "/traefik"
#      traefik.http.middlewares.traefik_stripprefix.stripPrefix.forceSlash: "true"
      # Define port for service
      traefik.http.services.traefik.loadbalancer.server.port: "8080"
    volumes:
      # Allow traefik to see other containers
      - "/var/run/docker.sock:/var/run/docker.sock"
    networks:
      - proxy
    ports:
      # Expose port 80 to handle web/http requests
      - "80:80"
      # For DEBUG: Expose port 8080 to see dashboard without routing
      # Will be removed when default rounting is working
      - "8080:8080"

networks:
  proxy:
    external: true

有人知道我错了吗?

最好的问候, 大卫

0 个答案:

没有答案
相关问题