最近在折腾traefik,个人感觉用traefik作为反向代理完全是大材小用了。并且traefik作为反向代理配置并没有nginx方便,主要是相关资料比较少,并且配置比较麻烦
真正的场景是在业务容器化内,这里给个测试成功example,完全把traefik当作nginx使用:
- docker-compose.yml:
version: '3'
services:
reverse-proxy:
# The official v2 Traefik docker image
image: traefik:v2.5
# Enables the web UI and tells Traefik to listen to docker
command: --api.insecure=true --providers.docker --providers.file.filename=/etc/traefik/router.yml
ports:
# The HTTP port
- "80:80"
# The Web UI (enabled by --api.insecure=true)
- "8080:8080"
volumes:
# So that Traefik can listen to the Docker events
- /etc/traefik/:/etc/traefik/:ro
- /var/run/docker.sock:/var/run/docker.sock
whoami:
image: containous/whoami
labels:
- "traefik.http.routers.mctest.rule=Host(`mctest.org`)"
- router.yml:
http:
routers:
transfor:
rule: "Path(`/transfor`)"
service: "service-transfor"
middlewares:
- "example"
services:
service-transfor:
loadBalancer:
servers:
- url: "http://10.10.3.219"
middlewares:
example:
stripPrefix:
prefixes:
- "/transfor"