为基本http配置traefik,让dashboard使用80端口--get page 404 not found

Configuring traefik for basic http so that dashboard uses port 80 -- get page 404 not found

我的 VPS 是 ubuntu 22.04 LTS headless

我在 /home/ubuntu 这样做,所以我有一个 ubuntu 用户是 sudoer。

已经安装docker并且运行宁Dockerversion 20.10.15, build fd82621

我的目的是 安装和 运行 traefik 成功地首先使用普通的 http。这是为了实现我的最终目标,即 运行 在同一个 VPS

上使用 somedemowebsite.com 下的子域分别使用多个应用程序

我的 Traefik 配置

这些是我在 /home/ubuntu

的步骤
mkdir traefik
cd traefik
mkdir data 
cd data
touch acme.json
chmod 600 acme.json
touch traefik.yml

这是我的/home/ubuntu/traefik/docker-compose.yml

version: '3.9'

services: 
  traefik: 
    image: traefik:v2.6 
    container_name: traefik 
    restart: unless-stopped 
    security_opt: 
      - no-new-privileges:true 
    networks: 
      - proxy 
    ports: 
      - 80:80 
      - 443:443 
      - 8080:8080
    volumes: 
      - /etc/localtime:/etc/localtime:ro 
      - /var/run/docker.sock:/var/run/docker.sock:ro 
      - /home/ubuntu/traefik/data/traefik.yml:/traefik.yml:ro 
      - /home/ubuntu/traefik/data/acme.json:/acme.json 
      - /home/ubuntu/traefik/data/config.yml:/config.yml:ro 
    labels: 
      - "traefik.enable=true" 
      - "traefik.http.routers.traefik.entrypoints=http" 
      - "traefik.http.routers.traefik.rule=Host(traefik.mydomaincom)" 
      - "traefik.http.middlewares.traefik-auth.basicauth.users=USER:BASIC_AUTH_PASSWORD" 
      - "traefik.http.routers.traefik.service=api@internal"

networks: 
  proxy: 
    external: true

这是我的/home/ubuntu/traefik/data/traefik.yml

api:
  dashboard: true
  debug: true
  insecure: true
entryPoints:
  http:
    address: ":80"
  https:
    address: ":443"
serversTransport:
  insecureSkipVerify: true
providers:
  docker:
    endpoint: "unix:///var/run/docker.sock"
    exposedByDefault: false
  file:
    filename: /config.yml
log:
  filePath: "/var/log/traefik.log"
  format: json
  level: DEBUG

DNS 设置

我正在为我的 DNS 使用 CloudFlare

somedemowebsite.com 的 CF 配置是

命令

/home/ubuntu/traefik 我做到了

docker network create proxy
docker compose up --force-recreate

我得到一个

[+] Running 1/0
⠿ Container traefik Created 0.1s
Attaching to traefik
traefik | time="2022-05-13T14:31:12Z" level=info msg="Configuration loaded from file: /traefik.yml"

我看到了什么

我在访问 http://traefik.somedemowebsite.com

时收到 404 页面未找到错误

如我所料

提示输入用户名和密码的基本身份验证

更新

当我使用端口 8080 时,我可以访问仪表板。但不能访问端口 80。

如何判断是什么原因导致这个404

我找到了这个https://doc.traefik.io/traefik/getting-started/faq/#404-not-found

有四个原因。我该如何调试才能知道是什么原因导致了我的 404?

我引用

  1. A request reaching an EntryPoint that has no Routers
  2. An HTTP request reaching an EntryPoint that has no HTTP Router
  3. An HTTPS request reaching an EntryPoint that has no HTTPS Router
  4. A request reaching an EntryPoint that has HTTP/HTTPS Routers that cannot be matched

我假设它不是 3,因为我明确地只使用 http。

如何判断它是 1、2 还是 4?

没关系我已经解决了

罪魁祸首是域没有用刻度线包裹。此外,为了使基本身份验证正常工作,我需要将中间件分配给路由器。

评论是做出改变的地方。所以对于 docker-compose.yml

version: '3.9'

services:
  traefik:
    image: traefik:v2.6
    container_name: traefik
    restart: unless-stopped
    security_opt:
      - no-new-privileges:true
    networks:
      - proxy
    ports:
      - 80:80
      - 443:443
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /home/ubuntu/traefik/data/traefik.yml:/traefik.yml:ro
      - /home/ubuntu/traefik/data/acme.json:/acme.json
      - /home/ubuntu/traefik/data/config.yml:/config.yml:ro
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.traefik.entrypoints=http"
      # notice the ticks
      - "traefik.http.routers.traefik.rule=Host(`traefik.mydomain`)"
      # added the middleware
      - "traefik.http.routers.traefik.middlewares=traefik-auth"
      - "traefik.http.middlewares.traefik-auth.basicauth.users=USER:BASIC_AUTH_PASSWORD"
      - "traefik.http.routers.traefik.service=api@internal"

networks:
  proxy:
    external: true