docker Traefik不会添加前缀

pkln4tw6  于 2022-11-22  发布在  Docker
关注(0)|答案(1)|浏览(219)

我正在尝试建立我的第一个家庭实验室。我已经有一些服务作为停靠容器运行,也让Traefik与它们一起工作。现在我想对我的PiHole示例做同样的事情。我已经让它工作,这样我就可以通过导航到“pihole.local.myurl.com/admin”来访问 Jmeter 板。但是,我想自动添加“/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

是不是我的码头布局出错了?

nhaq1z21

nhaq1z211#

您必须指定中间件的位置。在这种情况下,将@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

相关问题