【问题标题】:Traefik won't add prefixTraefik 不会添加前缀
【发布时间】:2022-11-17 08:23:12
【问题描述】:

我正在尝试建立我的第一个家庭实验室。 我已经有一些服务作为 docker-container 运行,并且让 Traefik 与它们一起工作。 我现在想对我的 PiHole 实例执行相同的操作。我已经让它工作了,所以我可以通过导航到“pihole.local.myurl.com/admin”来访问仪表板。但是,我想自动添加“/admin”前缀。

我用这个 docker-compose.yml 试过了,但是不会添加前缀:

version: "3"

# More info at https://github.com/pi-hole/docker-pi-hole/ and https://docs.pi-hole.net/
services:
  pihole:
    image: pihole/pihole:latest
    container_name: pihole
    restart: unless-stopped
    # For DHCP it is recommended to remove these ports and instead add: network_mode: "host"
    networks:
      - proxy
    ports:
      - "53:53/tcp"
      - "53:53/udp"
      #- "67:67/udp" # Only required if you are using Pi-hole as your DHCP server
      #- "8000:80/tcp"
    environment:
      TZ: 'Europe/Berlin'
      WEBPASSWORD: 'my_password'
    # Volumes store your data between container upgrades
    volumes:
      - './etc-pihole:/etc/pihole'
      - './etc-dnsmasq.d:/etc/dnsmasq.d'
      - './resolv.conf:/etc/resolv.conf'
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.pihole.entrypoints=http"
      - "traefik.http.routers.pihole.rule=Host(`pihole.local.myurl.com`)"
      - "traefik.http.middlewares.pihole-prefix.addPrefix.prefix=/admin"
      - "traefik.http.routers.pihole.middlewares=pihole-prefix"
      - "traefik.http.middlewares.pihole-https-redirect.redirectscheme.scheme=https"
      - "traefik.http.routers.pihole.middlewares=pihole-https-redirect"
      - "traefik.http.routers.pihole-secure.entrypoints=https"
      - "traefik.http.routers.pihole-secure.rule=Host(`pihole.local.myurl.com`)"
      - "traefik.http.routers.pihole-secure.tls=true"
      - "traefik.http.routers.pihole-secure.service=pihole"
      - "traefik.http.services.pihole.loadbalancer.server.port=80"
      - "traefik.docker.network=proxy"
    #   https://github.com/pi-hole/docker-pi-hole#note-on-capabilities
    #cap_add:
    #  - NET_ADMIN # Recommended but not required (DHCP needs NET_ADMIN)      

networks:
  proxy:
    external: true

我的 docker-compose 有错误吗?

【问题讨论】:

    标签: docker docker-compose traefik pihole


    【解决方案1】:

    您必须指定中间件的位置。在这种情况下,将 @docker 附加到您调用中间件的路由器行的末尾。 (标记第 5 行和第 7 行)

    例如:这是我为 Organizr 调用本地定义的和基于单独文件的中间件的组合:

          - traefik.enable=true
          ## HTTP Routers
          - traefik.http.routers.organizr-rtr.entrypoints=https
          - traefik.http.routers.organizr-rtr.rule=Host(`$DOMAINNAME`) || Host(`www.$DOMAINNAME`)
          ## Middlewares
          - traefik.http.routers.organizr-rtr.middlewares=organizr-redirect@docker,secure-headers@file
          ## Middlewares - Redirect to www
          - traefik.http.middlewares.organizr-redirect.redirectregex.permanent=true
          - traefik.http.middlewares.organizr-redirect.redirectregex.regex=^http(?:s)?://$DOMAINNAME/(.*)
          - traefik.http.middlewares.organizr-redirect.redirectregex.replacement=https://www.$DOMAINNAME/$${1}
          ## HTTP Services
          - traefik.http.routers.organizr-rtr.service=organizr-svc
          - traefik.http.services.organizr-svc.loadbalancer.server.port=80
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-07
      • 2020-09-10
      • 2017-07-23
      • 2014-09-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多