Define host and path frontend rule for Traefik

余生颓废 提交于 2020-07-18 04:02:04

问题


I am trying to use Traefik to deploy proxy multiple applications in my Docker Swarm mode cluster.

I have got it so that it proxies a named Host but I want it to proxy on a named Host and Path, but I cannot work out the labels I need to use.

This is the docker service command I am using:

 docker service create \
                       \
    --label "traefik.port=9000" \
    --label "traefik.docker.network=traefik-net" \
    --label "traefik.frontend.rule=Host:`hostname -f`" \
    --label="traefik.backend=portainer" \
                                        \
    --constraint "node.role == manager" \
    -p 9000:9000 \
    --mount "type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock" \
    --name portainer \
    portainer/portainer

If the host is dummy.localhost then I am able to hit the portainer app on http://dummy.localhost. However I want to modify it so that I have to use http://dummy.localhost/portainer.

I have seen that there are ways to do this when using a toml file for Traefik, but I am using watch mode and labels on the docker services I deploy.

How can I combine multiple front end rules in my labels so that this (and any other) application can be proxied on a hostname and a path?


回答1:


Traefik v1

If you want multiple rules to apply in order for a routing decision to become effective, separate them by semicolon. For instance:

Host: <your host rule>; PathPrefixStrip: /portainer

What the above means is: If the host and path prefix match, Traefik will route requests to the associated backend(s) (and strip off the specified path prefix prior to forwarding). This even works when defined inside a label.

See the frontend documentation for details.

Update: Traefik v2

Host(`domain.com`) && Path(`/path`)

See the docs



来源:https://stackoverflow.com/questions/44232354/define-host-and-path-frontend-rule-for-traefik

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!