我设置了Traefik来管理我的docker容器,但是我可以将我的域的www重定向到非www。我已经尝试了论坛中的所有内容,但没有运气
labels:
- "traefik.enable=true"
- "traefik.http.routers.node.entrypoints=http"
- "traefik.http.routers.node.rule=Host(`awebsite.com`) || Host(`www.awebsite.com`)"
- "traefik.http.middlewares.vk-https-redirect.redirectscheme.scheme=https"
- "traefik.http.middlewares.test-redirectregex.redirectregex.regex=^https://www.awebsite.com/(.*)"
- "traefik.http.middlewares.test-redirectregex.redirectregex.replacement=https://awebsite.com/$${1}"
- "traefik.http.routers.node.middlewares=vk-https-redirect"
- "traefik.http.routers.node-secure.entrypoints=https"
- "traefik.http.routers.node-secure.rule=Host(`awebsite.com`) || Host(`www.awebsite.com`)"
- "traefik.http.routers.node-secure.tls=true"
- "traefik.http.routers.node-secure.tls.certresolver=http"
- "traefik.http.routers.node-secure.service=node"
- "traefik.http.services.node.loadbalancer.server.port=8000"
- "traefik.docker.network=proxy"
答案 0 :(得分:5)
仅定义重定向中间件还不够,您还需要将其与定义的路由器一起使用
这是您的中间件定义
- "traefik.http.middlewares.test-redirectregex.redirectregex.regex=^https://www.awebsite.com/(.*)"
- "traefik.http.middlewares.test-redirectregex.redirectregex.replacement=https://awebsite.com/$${1}"
您可能还需要添加此标签
traefik.http.middlewares.test-redirectregex.redirectregex.permanent=true
,但是您从未在任何定义的路由器中使用过它。例如,如果要将其应用于node-secure
路由器,则需要添加此标签
- "traefik.http.routers.node-secure.middlewares=test-redirectregex"
更多信息,详细信息和示例,请参见此article
答案 1 :(得分:-1)
f<const char*>