gpt4 book ai didi

docker - 使用Docker标签时出现Traefik自定义错误页面

转载 作者:行者123 更新时间:2023-12-02 19:06:49 27 4
gpt4 key购买 nike

Traefik的更高版本支持自定义错误页面-能够在出现错误时将请求发送到其他后端。通常,当反向代理无法与应用程序服务器通信时,这是502。 This文档页面介绍了如何使用file后端类型执行此操作,并且效果很好。

但是,我正在尝试使用Docker后端。 This docs页面显示了预期的Docker配置-尽管目前尚不清楚<name>替换的含义。

因此,使用Docker Compose,我有一个基本设置,我想将所有HTTP 500-599流量定向到另一个后端,称为error。这是我在docker-compose.yml中得到的:

version: '2'
services:
traefik:
image: traefik
ports:
- "80:80"
- "8080:8080"
restart: always
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./acme:/etc/traefik/acme/
- ./traefik.toml:/etc/traefik/traefik.toml
hello:
image: kitematic/hello-world-nginx
ports:
- "80"
labels:
- traefik.backend=hello
- traefik.port=801
- traefik.frontend.rule=Host:localhost
- traefik.enable=true
- traefik.frontend.errors.network.status=["500-599"]
- traefik.frontend.errors.network.backend="error"
- traefik.frontend.errors.network.query="/500s.html"
error:
image: kitematic/hello-world-nginx
ports:
- "80"
volumes:
- ./html:/website_files
labels:
- "traefik.backend=error"
- "traefik.port=80"
- "traefik.frontend.rule=Host:error.localhost"
- "traefik.enable=true"

如您所见,我在 hello容器的发布端口和Traefik寻找的端口之间故意不匹配。这是为了强制 502 Bad Gateway错误。

我的 traefik.toml文件如下所示:
# defaultEntryPoints must be at the top because it should not be in any table below
defaultEntryPoints = ["http"]
# [accessLog]
logLevel = "DEBUG"

[web]
# Port for the status page
address = ":8080"

# Entrypoints, http and https
[entryPoints]

[entryPoints.http]
address = ":80"

[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "localhost"
watch = true
exposedbydefault = true
# swarmmode = true

但是,对 http://localhost的请求仍然返回通用的 Bad gateway消息,而不是重定向到 /500s.html容器提供的 error(直接进入 http://error.localhost/500s.html可以正常工作)

谢谢任何人的帮助!

最佳答案

关于docker - 使用Docker标签时出现Traefik自定义错误页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49673352/

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