traefik - simple modification of URL

邮差的信 提交于 2019-12-24 22:25:25

问题


I want to modify the endpoints of my URL, while it goes from traefik to one of my containers. What I want is this.
My URL looks like this - http://backend/asd and it should point to one of my containers with different endpoint like this - http://asd/dfg
What I tried -

  asd:
    image: asd
    container_name: "asd"
    labels:
      - "traefik.backend=asd"
      - "traefik.frontend.rule=Host:backend;PathPrefixStrip:/asd,PathPrefix:/dfg"
      - "traefik.frontend.entryPoints=http"
      - "traefik.enable=true"
      - "traefik.port=80"

But this didn't work. Any suggestions are welcome.
Regards,
Ashutosh


回答1:


Are you including a Traefik-docker-image in your docker-compose, like so?

traefik:
  image: traefik
  ports:
    - 8080:80
  volumes:
    - /var/run/docker.sock:/var/run/docker.sock
  command:
    - "--docker"

For your path-replacement "/asd" -> "/dfg", Traefik's ReplacePath-modifier should do the trick. This following docker-label is the only, you will need:

labels:
  - "traefik.frontend.rule=Path: /asd; ReplacePath: /dfg"

Having this setup, doing

curl http://localhost:8080/asd

should return the HTTP-response from your "asd"-container on path "/dfg"



来源:https://stackoverflow.com/questions/47269445/traefik-simple-modification-of-url

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