在配置链接中,traefik如何理解所有请求都应该代理到端口5000 。这显然没有在任何地方指出。但实际上,出于某种原因,当我访问 mydomain.com 时,我看到了Hello World。它是如何发生的?
配置
defaultEntryPoints = ["http", "https"]
[web]
address = ":8080"
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
[acme]
email = "test@traefik.io"
storageFile = "/etc/traefik/acme/acme.json"
entryPoint = "https"
onDemand = false
OnHostRule = true
# Use a HTTP-01 acme challenge rather than TLS-SNI-01 challenge
[acme.httpChallenge]
entryPoint = "http"
[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "example.com"
watch = true
exposedbydefault = false
我注意到在链接的示例中,使用了 1.7 版本,尽管没有明确指出。因此,以下是修改后的组成:
version: '2'
services:
flask:
build: ./flask
image: flask
command: uwsgi --http-socket 0.0.0.0:5000 --wsgi-file app.py --callable app
labels:
- "traefik.enable=true"
- "traefik.backend=flask"
- "traefik.frontend.rule=${TRAEFIK_FRONTEND_RULE}"
traefik:
image: traefik:v1.7.24
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./traefik/traefik.toml:/etc/traefik/traefik.toml:ro
- ./traefik/acme:/etc/traefik/acme
ports:
- "80:80"
- "443:443"
- "8080:8080"
traefik 反向代理的另一个链接
问题出在
docker-compose
. 因为traefik
你需要 installport
,它会监听应用程序,它可以通过域名获得:或者,它需要
EXPOSE 5000
在 docker 内显式完成。