【发布时间】:2018-07-16 18:04:27
【问题描述】:
我正在使用 docker-compose 将 Traefik 设置为在 Docker 容器中运行的几个服务的反向代理。我已经让它工作了,但我想做什么并且不确定如何配置它,以便通过不同的前端 https port 访问每个后端(而不是不同的子域或路径前缀)。
这是我的 Traefik 和第一个服务的 docker-compose 文件:
version: '3.2'
services:
traefik:
image: traefik:1.6-alpine
container_name: traefik
command:
- --logLevel=INFO
- --defaultentrypoints=http,https
- --entryPoints=Name:http Address::5099 Redirect.EntryPoint:https
- --entryPoints=Name:https Address::5098 TLS:/cert/certificate.crt,/cert/private.key
- --docker
- --docker.exposedbydefault=false
- --docker.domain=example.com
ports:
- target: 5099
published: 5099
protocol: tcp
mode: host
- target: 5098
published: 5098
protocol: tcp
mode: host
volumes:
- ./cert:/cert
- /var/run/docker.sock:/var/run/docker.sock
restart: always
firefox-syncserver:
image: crazymax/firefox-syncserver:latest
container_name: traefik-firefoxsync
volumes:
- ./firefoxsync:/data
labels:
- traefik.enable=true
- traefik.backend=firefox-syncserver
- traefik.port=5000
- traefik.frontend.rule=Host:example.com
environment:
- <...config for firefoxsync...>
restart: always
有了这个,我可以通过https://example.com:5098 访问服务,一切都很好。现在让我们尝试添加第二个服务:
traefik-manictime:
image: manictime/manictimeserver:latest
container_name: traefik-manictime
volumes:
- ./manictime:/app/Data
labels:
- traefik.enable=true
- traefik.backend=manictime
- traefik.port=8080
- traefik.frontend.rule=PathPrefix:/manictime
restart: always
可通过https://example.com:5098/manictime 访问。但是,问题是服务本身不能在虚拟目录中运行(也就是它需要在其域的顶级 - 没有 /manictime 子目录)。虽然我知道我可以使用子域而不是路径前缀来区分服务,但我更喜欢使用端口(其中一个原因是我将它托管在家里的 NAS 上,这不是静态 IP,所以我正在使用 DDNS 将顶级域指向正确的位置;必须为每个子域都这样做很麻烦)。
所以问题是:我可以以某种方式配置 Traefik 以便即
https://example.com:5098 -> https 前端到服务 1
https://example.com:6000 -> https 前端到服务 2
?
【问题讨论】:
标签: docker docker-compose reverse-proxy traefik