为基本HTTP配置Traefik,以便仪表板使用端口80-获取页面404找不到

发布于 2025-01-28 08:34:03 字数 3324 浏览 3 评论 0原文

我的VPS是Ubuntu 22.04 LTS无头,

我正在以/home/ubuntu进行此操作,因此我有一个ubuntu用户是Sudoer。

已经安装了Docker并运行Docker 版本20.10.15,Build FD82621

我的目的是 http oft http http first first 成功地安装和运行traefik。这是为了朝着我的最终目标建立运行多个应用程序,每个应用程序使用>>> ameedemowebsite.com在同一vps上

我的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/home/ubuntu/traefik/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设置

,我正在使用Cloudflare for Cloudflare。我的DNS

我的CF配置someDemowebsite.com

  • ssl/tls加密模式(不安全)
  • SSL/TLS推荐人是的是,
  • 始终

/

/home/home/ubuntu/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

我期望

提示用户名的基本auth和密码

更新

我可以使用端口8080时可以到达仪表板。但不能端口80。

如何分辨出哪个原因是因为这个404

我发现此 https://doc.traefik.io/traefik/getting-started/faq/faq/#404-not-found

有4个原因。我如何以某种方式进行调试,我可以知道造成404的原因是什么?

我引用

  1. 到达没有路由器的入口点的请求
  2. HTTP请求到达没有HTTP路由器的入口点
  3. HTTPS请求到达没有HTTPS路由器的入口点
  4. 到达具有无法匹配的HTTP/HTTPS路由器的入口点的请求

入口点,该请求 3因为我明确使用HTTP。

我该如何确定是1、2还是4?

My VPS is a ubuntu 22.04 LTS headless

I am doing this at /home/ubuntu so I have a ubuntu user that's a sudoer.

Already installed docker and running Docker version 20.10.15, build fd82621

My purpose is to install and run traefik successfully with just plain http first. It's to build towards my ultimate goal of running multiple apps each using a subdomain under somedemowebsite.com on the same VPS

My Traefik Configuration

These are my steps at /home/ubuntu

mkdir traefik
cd traefik
mkdir data 
cd data
touch acme.json
chmod 600 acme.json
touch traefik.yml

This is my /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

This is my /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 settings

I am using CloudFlare for my DNS

My CF configurations for somedemowebsite.com is

  • SSL/TLS encryption mode is Off (not secure)
  • SSL/TLS Recommender Yes
  • Always Use HTTPS No

Commands

At /home/ubuntu/traefik I did

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

I get a

[+] 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"

What I saw

I get a page 404 not found error when I went to http://traefik.somedemowebsite.com

What i expected

to get prompted for basic auth for username and password

Update

I can reach the dashboard when I use port 8080. but not port 80.

how to tell which reason cause this 404

I found this https://doc.traefik.io/traefik/getting-started/faq/#404-not-found

there are 4 reasons. How do I debug in a way I can know which reason caused my 404?

I cite

  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

I assume it's not 3 since I am explicitly only using http.

How do I tell whether it's 1, 2, or 4?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

唠甜嗑 2025-02-04 08:34:03

没关系,我已经解决了它。

主要的罪魁祸首是该域没有包裹在tick中。同样,要使基本验证工作能够工作,我需要将中间件分配给路由器。

评论是更改使事情起作用的地方。因此,对于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

Never mind I have solved it.

The main culprit is that the domain is not wrapped in ticks. Also for the basic auth to work i need to assign the middleware to the router.

Comments are where the changes made things work. So for 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文