Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
455 views
in Technique[技术] by (71.8m points)

traefik - simple modification of URL

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...