gpt4 book ai didi

docker - Traefik 版本 2 仅显示 404 或根本没有网站

转载 作者:行者123 更新时间:2023-12-02 06:32:56 25 4
gpt4 key购买 nike

我尝试在版本 2 中设置 Traefik,但在浏览器中只收到“404 页面未找到”或 DNS_PROBE_FINISHED_NXDOMAIN 错误。

当我检查路由器的 API 端点时,我可以看到我的两个容器已在 Traefik 中启用,并且规则是正确的。

curl http://localhost:8080/api/http/routers

[{"entryPoints":["web","secure"],"service":"gotify-gotify","rule":"Host(`sub2.example.org`)","tls":{"certResolver":"letsencrypt"},"status":"enabled","using":["secure","web"],"name":"gotify@docker","provider":"docker"},{"entryPoints":["web","secure"],"service":"nextcloud-cloud","rule":"Host(`sub.example.org`)","tls":{"certResolver":"letsencrypt"},"status":"enabled","using":["secure","web"],"name":"nextcloud@docker","provider":"docker"}]

但是在“sub2”上我根本没有任何网站,在“sub”上我得到“404 页面未找到”。我已经为“*”设置了一个 DNS 条目,因此所有子域都转到同一服务器。

我为 docker 容器设置了以下标签

labels:
traefik.enable: true
traefik.http.routers.nextcloud.rule: "Host(`sub.example.org`)"
traefik.http.routers.nextcloud.entrypoints: "web, secure"
traefik.http.routers.nextcloud.tls.certresolver: "letsencrypt"

这是我的 Traefik 配置 traefik.toml

[entryPoints]
[entryPoints.web]
address = ":80"
[entryPoints.secure]
address = ":443"

[providers.docker]
exposedByDefault = false
network = "traefik"

[certificatesResolvers.letsencrypt.acme]
email = "me@example.org"
storage = "acme.json"
[certificatesResolvers.letsencrypt.acme.httpChallenge]
entryPoint = "web"

[api]
insecure = true
debug = true
dashboard = false

Traefik 本身作为 Docker 容器运行。

version: "3.7"

services:
traefik:
image: traefik:v2.0
container_name: traefik
restart: unless-stopped
volumes:
- "./traefik.toml:/etc/traefik/traefik.toml"
- "./acme:/etc/traefik/acme"
- "/var/run/docker.sock:/var/run/docker.sock"
ports:
- "80:80"
- "127.0.0.1:8080:8080"
- "443:443"
networks:
- traefik

networks:
traefik:
driver: bridge
name: traefik

我使用ufw来管理防火墙规则并打开端口22、80和443

Status: active

To Action From
-- ------ ----
22/tcp ALLOW Anywhere
80/tcp ALLOW Anywhere
443/tcp ALLOW Anywhere
22/tcp (v6) ALLOW Anywhere (v6)
80/tcp (v6) ALLOW Anywhere (v6)
443/tcp (v6) ALLOW Anywhere (v6)

最佳答案

您可以找到 traefik 2.2.1 的工作示例。此外,您还可以查看完整的设置要点:https://gist.github.com/fatihyildizhan/8f124039a9bd3801f0caf3c01c3601fb

我更喜欢在 2.0 版本中使用 traefik.yml。看起来很简单,很多人都熟悉 YAML 文件。

[Traefik v2.0] - docker-compose.yml  with httpChallenge

version: '3.7'

services:
traefik:
image: traefik:v2.2.1
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
- ./traefik.yml:/traefik.yml:ro
- ./acme.json:/acme.json
labels:
- "traefik.enable=true"
- "traefik.http.routers.traefik.entrypoints=http"
- "traefik.http.routers.traefik.rule=Host(`traefik.your-domain.com`)"
- "traefik.http.middlewares.traefik-auth.basicauth.users=username:hashed-password"
- "traefik.http.middlewares.traefik-https-redirect.redirectscheme.scheme=https"
- "traefik.http.routers.traefik.middlewares=traefik-https-redirect"
- "traefik.http.routers.traefik-secure.entrypoints=https"
- "traefik.http.routers.traefik-secure.rule=Host(`traefik.your-domain.com`)"
- "traefik.http.routers.traefik-secure.middlewares=traefik-auth"
- "traefik.http.routers.traefik-secure.tls=true"
- "traefik.http.routers.traefik-secure.tls.certresolver=http"
- "traefik.http.routers.traefik-secure.service=api@internal"
- "traefik.http.services.traefik.loadbalancer.server.port=8080"

networks:
proxy:
external: true


[Traefik v2.0] - traefik.yml with httpChallenge

api:
dashboard: true

# Writing Logs to a File, in JSON
log:
level: DEBUG
filePath: "log-file.log"
format: json

# Configuring a buffer of 100 lines
accessLog:
filePath: "log-access.log"
bufferingSize: 100

entryPoints:
http:
address: ":80"
https:
address: ":443"

providers:
docker:
endpoint: "unix:///var/run/docker.sock"
exposedByDefault: false

certificatesResolvers:
http:
acme:
email: your-email.com
storage: acme.json
httpChallenge:
entryPoint: http


[Traefik v2.0] - your-container docker-compose.yml

version: '3.7'

services:
your-container-name:
image: docker.pkg.github.com/username/repo-name/image-name:latest
container_name: your-container-name
restart: unless-stopped
security_opt:
- no-new-privileges:true
networks:
- proxy
volumes:
- /etc/localtime:/etc/localtime:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./data:/data
labels:
- "traefik.enable=true"
- "traefik.http.routers.your-container-name.entrypoints=http"
- "traefik.http.routers.your-container-name.rule=Host(`your-container-name.your-domain.com`)"
- "traefik.http.middlewares.your-container-name-https-redirect.redirectscheme.scheme=https"
- "traefik.http.routers.your-container-name.middlewares=your-container-name-https-redirect"
- "traefik.http.routers.your-container-name-secure.entrypoints=https"
- "traefik.http.routers.your-container-name-secure.rule=Host(`your-container-name.your-domain.com`)"
- "traefik.http.routers.your-container-name-secure.tls=true"
- "traefik.http.routers.your-container-name-secure.tls.certresolver=http"
- "traefik.http.routers.your-container-name-secure.service=your-container-name"
- "traefik.http.services.your-container-name.loadbalancer.server.port=80"
- "traefik.docker.network=proxy"

networks:
proxy:
external: true

关于docker - Traefik 版本 2 仅显示 404 或根本没有网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58138650/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com