一段时间以来,我一直尝试在我的 Oracle Cloud VPS 上设置 Traefik。该服务器位于 Cloudflare 后面,因此我配置了来自他们的原始证书。这似乎有效,因为当我想要访问仪表板时,配置的证书就会被传送。不幸的是,Traefik 似乎无法正确路由到仪表板,因为404
当我访问配置的路径时,我总是得到一个返回:https://proxy.example.com/dashboard/
。
我的docker-compose.yml
样子是这样的:
version: '3'
networks:
proxy:
name: proxy
services:
proxy:
image: traefik:2.8
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./traefik.yml:/traefik.yml
- ./tls.yml:/tls.yml
- ./cloudflare.crt:/cloudflare.crt
- ./cloudflare.key:/cloudflare.key
ports:
- target: 80
published: 80
mode: host
- target: 443
published: 443
mode: host
labels:
- "traefik.enable=true"
- "traefik.http.routers.dashboard-https.rule=Host(`proxy.example.com`) && (PathPrefix(`/api`) || PathPrefix(`/dashboard`))"
- "traefik.http.routers.dashboard-https.entrypoints=https"
- "traefik.http.routers.dashboard-https.service=api@internal"
networks:
- proxy
看起来traefik.yml
像:
log:
level: DEBUG
api:
insecure: false
dashboard: true
entryPoints:
https:
address: ":443"
providers:
docker:
network: proxy
endpoint: "unix:///var/run/docker.sock"
exposedByDefault: false
file:
filename: "tls.yml"
watch: true
我tls.yml
把以下内容放在这里:
tls:
certificates:
- certFile: "/cloudflare.crt"
keyFile: "/cloudflare.key"
stores:
default:
defaultCertificate:
certFile: "/cloudflare.crt"
keyFile: "/cloudflare.key"
该文件夹包含以下内容:
cloudflare.crt cloudflare.key docker-compose.yml tls.yml traefik.yml
到目前为止我已经尝试了很多事情:
- 通过接受
INPUT
、OUTPUT
和上的所有内容来禁用 iptablesFORWARD
。 - 跑步另一项服务在 Docker 上并直接公开其 http 接口而无需 Traefik,这是可行的。
- 直接在主机系统上运行服务器(无需 Docker)并测试 http 接口是否可以访问,同样有效。
我很确定我的 Traefik 配置有问题。你看到我犯了什么错误吗?
答案1
如果仅配置了 https,则tls
需要设置为true
,否则 Traefik 将不会路由到指定的服务。
version: '3'
networks:
proxy:
name: proxy
services:
proxy:
image: traefik:2.8
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./traefik.yml:/traefik.yml
- ./tls.yml:/tls.yml
- ./cloudflare.crt:/cloudflare.crt
- ./cloudflare.key:/cloudflare.key
ports:
- target: 443
published: 443
mode: host
labels:
- "traefik.enable=true"
# The line below was missing.
- "traefik.http.routers.dashboard.tls=true"
- "traefik.http.routers.dashboard.rule=Host(`proxy.example.com`) && (PathPrefix(`/api`) || PathPrefix(`/dashboard`))"
- "traefik.http.routers.dashboard.entrypoints=https"
- "traefik.http.routers.dashboard.service=api@internal"
networks:
- proxy