x4k*_*k3p 8 load-balancing docker bad-gateway traefik
我有一些奇怪的问题。我有以下设置:一个 docker-host 运行 traefik 作为 LB,为多个站点提供服务。网站大多是 php/apache。HTTPS 由 traefik 管理。每个站点都使用包含以下内容的 docker-compose YAML 启动:
version: '2.3'
services:
redis:
image: redis:alpine
container_name: ${PROJECT}-redis
networks:
- internal
php:
image: registry.gitlab.com/OUR_NAMESPACE/docker/php:${PHP_IMAGE_TAG}
environment:
- APACHE_DOCUMENT_ROOT=${APACHE_DOCUMENT_ROOT}
container_name: ${PROJECT}-php-fpm
volumes:
- ${PROJECT_PATH}:/var/www/html:cached
- .docker/php/php-ini-overrides.ini:/usr/local/etc/php/conf.d/99-overrides.ini
ports:
- 80
networks:
- proxy
- internal
labels:
- traefik.enable=true
- traefik.port=80
- traefik.frontend.headers.SSLRedirect=false
- traefik.frontend.rule=Host:${PROJECT}
- "traefik.docker.network=proxy"
networks:
proxy:
external:
name: proxy
internal:
Run Code Online (Sandbox Code Playgroud)
(作为 PHP,我们使用 5.6.33-apache-jessie 或 7.1.12-apache fe)
除了上述之外,一些网站还获得以下标签:
traefik.docker.network=proxy
traefik.enable=true
traefik.frontend.headers.SSLRedirect=true
traefik.frontend.rule=Host:example.com, www.example.com
traefik.port=80
traefik.protocol=http
Run Code Online (Sandbox Code Playgroud)
我们得到的是一些请求以 502 Bad Gateway traefik 调试输出结束:
time="2018-03-21T12:20:21Z" level=debug msg="vulcand/oxy/forward/http: Round trip: http://172.18.0.8:80, code: 502, Length: 11, duration: 2.516057159s"
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?当它发生在我们的 traefik.toml 时,它是完全随机的:
debug = true
checkNewVersion = true
logLevel = "DEBUG"
defaultEntryPoints = ["https", "http"]
[accessLog]
[web]
address = ":8080"
[web.auth.digest]
users = ["admin:traefik:some-encoded-pass"]
[entryPoints]
[entryPoints.http]
address = ":80"
# [entryPoints.http.redirect] # had to disable this because HTTPS must be enable manually (not my decission)
# entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
[retry]
[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "example.com"
watch = true
exposedbydefault = false
[acme]
email = "info@example.com"
storage = "acme.json"
entryPoint = "https"
onHostRule = true
[acme.httpChallenge]
entryPoint = "http"
Run Code Online (Sandbox Code Playgroud)
该问题是否与使用相同的 docker-compose.yml 有关?
Meh*_*ein 22
另一个原因可能是您可能意外映射到虚拟机的端口而不是容器端口。
我对 docker-compose 文件上的端口映射进行了更改,但忘记更新标记的端口,因此它试图映射到计算机上没有附加任何进程的端口
错误的方法:
ports:
- "8080:8081"
labels:
- "traefik.http.services.front-web.loadbalancer.server.port=8080"
Run Code Online (Sandbox Code Playgroud)
正确的方法
ports:
- "8080:8081"
labels:
- "traefik.http.services.front-web.loadbalancer.server.port=8081"
Run Code Online (Sandbox Code Playgroud)
一般来说,不要这样做,不要暴露端口,尝试使用 docker 网络,它们更好、更干净。我一年前就制作了配置文档,这对我来说更像是一个初学者错误,但可能会对某人有所帮助:)
如果您Bad Gateway使用 Traefik看到可能是 Docker 网络问题。首先看看这个问题并考虑这个解决方案。然后看看providers.docker.network(Traefik 2.0) 或者,在你的情况下,docker.network设置 (Traefik 1.7)。
您可以network在此处添加默认值:
[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "example.com"
watch = true
exposedbydefault = false
network = "proxy"
Run Code Online (Sandbox Code Playgroud)
或者使用traefik.docker.network标签为给定服务定义/覆盖它。
遇到了同样的问题,上述答案都没有为我解决。就我而言,添加了错误的负载均衡器。去掉标签或将其更换到正确的端口就可以了。
- "traefik.http.services.XXX.loadbalancer.server.port=XXX"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
33477 次 |
| 最近记录: |