賞金將在 6 天后到期。此問題的答案有資格獲得 200聲望賞金。 Kim Stacks希望引起對這個問題的更多關注。
我的 VPS 是 ubuntu 22.04 LTS 無頭
我正在這樣做,/home/ubuntu所以我有ubuntu一個 sudoer 用戶。
已經安裝 docker 并運行 Dockerversion 20.10.15, build fd82621
我的目的是先使用普通的 http 成功安裝和運行 traefik。這是為了實作我的最終目標,somedemowebsite.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/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
我的 CF 配置somedemowebsite.com是
- SSL/TLS 加密模式關閉(不安全)
- SSL/TLS 推薦器 是
- 始終使用 HTTPS 否
命令
在/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"
我所看到的
當我去的時候,我得到一個頁面 404 not found 錯誤http://traefik.somedemowebsite.com
我所期望的
提示輸入用戶名和密碼的基本身份驗證
更新
當我使用埠 8080 時,我可以訪問儀表板。但不是埠 80。
如何判斷導致此 404 的原因
我發現了這個https://doc.traefik.io/traefik/getting-started/faq/#404-not-found
有4個原因。如何以一種我可以知道導致我的 404 的原因的方式進行除錯?
我參考
- 到達沒有路由器的入口點的請求
- 到達沒有 HTTP 路由器的入口點的 HTTP 請求
- 到達沒有 HTTPS 路由器的入口點的 HTTPS 請求
- 到達具有無法匹配的 HTTP/HTTPS 路由器的入口點的請求
我認為它不是 3,因為我明確地只使用 http。
如何判斷它是 1、2 還是 4?
uj5u.com熱心網友回復:
沒關系,我已經解決了。
罪魁禍首是域沒有被包含在刻度中。此外,為了使基本身份驗證正常作業,我需要將中間件分配給路由器。
評論是更改使事情起作用的地方。因此對于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
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/474938.html
