简体   繁体   中英

traefik v2 forward domain requests to subroute

I have a react web app built with docker and is behind Traefik proxy. The Docker container has Nginx on port 80 as an HTTP server for the react application. Current config sets http://example.com & https://example.com to react app. I want to forward another domain requests to a subroute of application, for example, forward https://test.example.com requests to https://example.com/test-sub-route . How can I do this with Traefik v2?

Note : The address bar should show https://test.example.com .

This is my current configuration:

version: "3.7"

services:

  reactweb:
    image: react-web-app:latest
    networks:
      - 'internal'
      - 'traefik'
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=traefik"
      - "traefik.http.routers.reactweb-web.entrypoints=web"
      - "traefik.http.routers.reactweb-web.rule=Host(`example.com`)"
      - "traefik.http.middlewares.reactweb-redirect.redirectscheme.scheme=https"
      - "traefik.http.middlewares.reactweb-redirect.redirectscheme.permanent=true"
      - "traefik.http.routers.reactweb-web.middlewares=reactweb-redirect@docker"
      - "traefik.http.routers.reactweb-websecure.entrypoints=websecure"
      - "traefik.http.routers.reactweb-websecure.rule=Host(`example.com`)"
      - "traefik.http.routers.reactweb-websecure.tls=true"
      - "traefik.http.services.reactweb-service.loadbalancer.server.port=80"


networks:
  traefik:
    external: true
  internal:
    external: false

You can add the prefix in the path in traefik. Use the below code snippet.

labels:
  - "traefik.http.middlewares.add-foo.addprefix.prefix=/foo"

Reference: https://docs.traefik.io/middlewares/addprefix/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM