简体   繁体   中英

Traefik rule need solution for sub domain

I want to run an application behind traefik not as a sub-domain, but something like: xyz.abc.com/m1 or xyz.abc.com/m2 and so on. Which label will work for it. I have tried with PathPrefix but it's not working. A sample application Joomla is deployed on docker swarm mode. Can I use Nginx or Haproxy for the same?? If so, How?

When putting multiple applications behind the same name, there's a good chance the app needs to know it's URL prefix isn't at root (as most apps are expecting to be deployed at the root). So, might need to look at that too.

Traefik-wise, a stack file might look like this. This is running in Swarm mode (since you mentioned Swarm), which requires the Traefik labels to be on the service, not on the container. As such, they have to be within the deploy.labels definition, not just labels .

Example using Traefik 1

version: "3.7"

services:
  proxy:
    image: traefik:1.7
    command: --docker --docker.swarmMode
    ports:
      - 80:80
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

  app1:
    image: your-image-for-app1
    deploy:
      labels:
        traefik.backend: app1
        traefik.frontend.rule: PathPrefix:/m1
        traefik.port: 80

  app2:
    image: your-image-for-app2
    deploy:
      labels:
        traefik.backend: app2
        traefik.frontend.rule: PathPrefix:/m2
        traefik.port: 80

Example using Traefik 2

version: "3.7"

services:
  proxy:
    image: traefik:2.0
    command: --providers.docker --providers.docker.swarmMode
    ports:
      - 80:80
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

  app1:
    image: your-image-for-app1
    deploy:
      labels:
        traefik.http.routers.app1.rule: PathPrefix(`/m1`)
        traefik.http.services.app1.loadbalancer.server.port: 80

  app2:
    image: your-image-for-app2
    deploy:
      labels:
        traefik.http.routers.app2.rule: PathPrefix(`/m2`)
        traefik.http.services.app2.loadbalancer.server.port: 80

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