Treafik重定向就像魅力一样!
如何配置要显示的 Traefik仪表板?
我有一个指向我的域的“ A”记录和一个指向同一域的CNAME记录“监视器”。 对吗?
我的第一次尝试是这个docker-compose.yml文件。它还包含一个监听8080的Spring Boot应用程序:
version: '3'
services:
traefik:
image: traefik:latest
container_name: traefik
command: --api --docker
restart: always
networks:
- geosolutionsnet
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /home/ec2-user/traefik/traefik.toml:/traefik.toml
- /home/ec2-user/traefik/acme.json:/acme.json
ports:
- "80:80"
- "443:443"
labels:
- "traefik.docker.network=geosolutionsnet"
- "traefik.enable=true"
- "traefik.frontend.rule=Host:monitor.xyz.nl"
- "traefik.port=8080"
- "traefik.protocol=http"
#- "traefik.frontend.headers.STSSeconds=15768000"
在浏览器中,我指向“ monitor.xyz.nl”,但我得到了404。
我的第二次尝试是:
- "traefik.frontend.rule=Host:xyz.nl;Path:/monitor"
将浏览器指向xyz.nl/monitor ...再次给出了404。
我的traefik.toml文件是:
defaultEntryPoints = ["http", "https"]
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "xyz.nl"
watch = true
exposedByDefault = false
[acme]
email = "jj@xyz.nl"
storage = "acme.json"
onHostRule = true
entryPoint = "https"
onDemand = false
[acme.tlsChallenge]
更新: 使用映射到域'xyz.nl/traefik'的CNAME'traefik'会导致404错误。
使用指向(A记录)域的CNAME“监视器”,我得到相同的结果。我认为这很正常,因为我通过pathprefix配置了主机匹配。
答案 0 :(得分:2)
docker-compose.yml
services:
traefik:
image: traefik:latest
container_name: traefik
restart: always
networks:
- geosolutionsnet
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /home/ec2-user/traefik/traefik.toml:/traefik.toml
- /home/ec2-user/traefik/acme.json:/acme.json
ports:
- "80:80"
- "443:443"
labels:
- "traefik.docker.network=geosolutionsnet"
- "traefik.enable=true"
- "traefik.frontend.rule=Host:xyz.nl;PathPrefix:/monitor" # <----
- "traefik.port=8080"
treafik.toml
defaultEntryPoints = ["http", "https"]
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
[api]
[docker]
domain = "xyz.nl"
exposedByDefault = false
[acme]
email = "jj@xyz.nl"
storage = "acme.json"
onHostRule = true
entryPoint = "https"
onDemand = false
[acme.tlsChallenge]
我建议不要在同一部分(例如--docker
和[docker]
)中混合使用CLI参数和TOML
答案 1 :(得分:1)
在Docker compose中,我添加到traefik部分端口8080:8080。
然后,通过导航到端口8080来显示Traefik仪表板。重要的是通过'http'和 NOT 'https'进行导航。
下一个改进是使用HTTPS,这样就不会有不友好的人访问Traefik仪表板。