Configuration for multiple app

Hi !

I need some pointers :slight_smile:
Right now I have traefik installed and running on my DO with a subdomain my.domain.com.
I also have an app (Blazegraph datatourisme / docker-stack ยท GitLab ) installed with docker.
This app makes available 3 urls :

  • serverip:9999/blazegraph/
  • serverip:8080/graphiql
  • serverip:8080/voyager

Now, I'd like to know if I can :

  • At least, use my.domain.com instead of serverip by using traefik (and how please :smiley: )
  • At best, use other subdomains for each urls (like my1.domain for serverip:9999/blazegraph/ , my2.domain for serverip:8080/graphiql ... )

Thanks a lot !

Hello @Mat !

You add host-based and pathprefix routes like:

- traefik.enable=true
- traefik.http.services.SERVICENAME1.loadbalancer.server.port=9999
- traefik.http.routers.SERVICENAME1.service=SERVICENAME1
- traefik.http.routers.SERVICENAME1.entrypoints=web
- traefik.http.routers.SERVICENAME1.rule=Host(`my1.domain`) && PathPrefix(`/blazegraph/`)
- traefik.enable=true
- traefik.http.services.SERVICENAME2.loadbalancer.server.port=8080
- traefik.http.routers.SERVICENAME2.service=SERVICENAME2
- traefik.http.routers.SERVICENAME2.entrypoints=web
- traefik.http.routers.SERVICENAME2.rule=Host(`my2.domain`) && PathPrefix(`/graphiql/`)

Greetings from Brazil!

1 Like

Thank you so much for your reply :slight_smile:
I feel pretty stupid but I don't understand where I have to add that.
I assume that I have to modify my traefik.toml, but I don't know where to start.

Right now it's the basic file :

[entryPoints]
  [entryPoints.web]
    address = ":80"
    [entryPoints.web.http.redirections.entryPoint]
      to = "websecure"
      scheme = "https"

  [entryPoints.websecure]
    address = ":443"

[api]
  dashboard = true

[certificatesResolvers.lets-encrypt.acme]
  email = "mathieu@me"
  storage = "acme.json"
  [certificatesResolvers.lets-encrypt.acme.tlsChallenge]

[providers.docker]
  watch = true
  network = "web"

[providers.file]
  filename = "traefik_dynamic.toml"

I've tried to understand the doc but it's kinda hard to get it for me :slight_smile:

Should I had something like that at the end of the traefik.toml ?

[services]
  [services.bgcontainer]  
  	traefik.enable = true
  	traefik.http.services.SERVICENAME1.loadbalancer.server.port = 9999
	traefik.http.routers.SERVICENAME1.service = SERVICENAME1
	traefik.http.routers.SERVICENAME1.entrypoints = web
	traefik.http.routers.SERVICENAME1.rule=Host(`my1.domain`) && PathPrefix(`/blazegraph/`)
	
  [services.gqlcontainer] 
	traefik.enable = true
	traefik.http.services.SERVICENAME2.loadbalancer.server.port = 8080
	traefik.http.routers.SERVICENAME2.service = SERVICENAME2
	traefik.http.routers.SERVICENAME2.entrypoints = web
	traefik.http.routers.SERVICENAME2.rule=Host(`my2.domain`) && PathPrefix(`/graphql/`)

Thanks a lot !!

Don't feel stupid! Traefik is a relatively new tool and we are constantly learning. All of us, without exception!

Based on your stack available in gitlab, you could do it as follows.

version: '3.1'

services:

  blazegraph:
    image: conjecto/blazegraph:2.1.5
    restart: always
    #ports:
    #  - 9999:9999
    environment:
        JAVA_OPTS: "-Xms512m -Xmx1g"
    volumes:
      - ./dataset:/docker-entrypoint-initdb.d
    deploy:
    restart_policy:
      condition: any
    mode: global
    endpoint_mode: dnsrr
    placement:
      constraints: [node.role == worker]
    update_config:
      delay: 2s
    labels:
      - traefik.enable=true
      - traefik.http.services.blazegraph.loadbalancer.server.port=9999
      - traefik.http.routers.blazegraph.rule=Host(`my1.domain`) && PathPrefix(`/blazegraph/`)
      - traefik.http.routers.blazegraph.service=blazegraph
      - traefik.http.services.blazegraph.loadbalancer.sticky=true
      
      # If you need sticky sessions, please uncomment below
      #- traefik.http.services.blazegraph.loadbalancer.sticky.cookie.name=StickyCookie
      #- traefik.http.services.blazegraph.loadbalancer.sticky.cookie.httponly=true
      #- traefik.http.services.blazegraph.loadbalancer.sticky.cookie.secure=true

      # Enable Secure Configuration
      - traefik.http.routers.blazegraph.tls=true
      - traefik.http.routers.blazegraph.entrypoints=websecure

      # Lets Encrypt Resolver
      - traefik.http.routers.blazegraph.tls.certresolver=lets-encrypt

Guys!

It's possible to do somethink like your talking about over here, but add prefix for service2 in another service1 domain?

I mean, I got ha.domain.com and vsc.domain.com, how I can add prefix for vsc.domain.com for looks like this: ha.domain.com/vscode --> for redirected or opened by this link my second service at vsc.domain.com?

@SoulAssassin Would you have a stack example for better understanding?

Sure!

Here is one:

version: '3.9'
services:

  homeassistant:
    container_name: homeassistant
    image: ghcr.io/home-assistant/home-assistant:beta
    volumes:
      - /homeassistant:/config
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock
    restart: unless-stopped
    privileged: true
    network_mode: host
    depends_on:
      homeassistant-db:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-f", "http://10.20.0.4:8123"]
      interval: 60s
      timeout: 30s
      retries: 6
    labels:
      - diun.enable=true
      - com.centurylinklabs.watchtower.scope=watchtower-homeassistant
      - traefik.enable=true
      - traefik.http.services.homeassistant.loadbalancer.server.port=8123
      - traefik.http.routers.homeassistant.rule=Host(`ha.domain.com`)
      - traefik.http.routers.homeassistant.entrypoints=websecure
      - traefik.http.routers.homeassistant.tls=true
      - traefik.http.routers.homeassistant.tls.certresolver=myresolver

  homeassistant-vscode:
    container_name: homeassistant-vscode
    image: codercom/code-server:latest
    volumes:
      - /homeassistant:/home/coder/project
      - /vscode:/home/coder/.local/share/code-server
    ports:
      - 8080:8443
    command: code-server --auth password --port 8443 --disable-telemetry /home/coder/project
    environment:
      - PASSWORD=${VSCODE_PASSWORD}
    restart: unless-stopped
    labels:
      - diun.enable=true
      - com.centurylinklabs.watchtower.scope=watchtower-system
      - traefik.enable=true
      - traefik.http.services.homeassistant-vscode.loadbalancer.server.port=8443
      - traefik.http.routers.homeassistant-vscode.rule=Host(`vsc.domain.com`)
      #- traefik.http.routers.homeassistant-vscode.rule=Host(`domain.com`) && PathPrefix(`/vscode/`)
      - traefik.http.routers.homeassistant-vscode.entrypoints=websecure
      - traefik.http.routers.homeassistant-vscode.tls=true
      - traefik.http.routers.homeassistant-vscode.tls.certresolver=myresolver
      #- traefik.http.routers.homeassistant-vscode.middlewares=custom_repath
      #- traefik.http.middlewares.custom_repath.replacepathregex.regex=^/$$
      #- traefik.http.middlewares.custom_repath.replacepathregex.replacement=/vscode
      #- traefik.http.routers.homeassistant-vscode.tls.certresolver=le

As u can see, two services, ha.domain.com and vsc.domain.com, and when I open Home Assistant via https (ha.domain.com), inside link to my vscode container get formatted like ha.domain.com/vscode <-- so this is a qustion, how I can (if I can) add rule for maybe prefix or something else, with helped me to add additional path like ha.domain.com/vscode for opens my vscode application. I hope I described it all clear. Thanks. :+1:

Perfect! I believe I understand.

So internally in your application there is already a redirect from / to /vscode

You can use redirectregex middleware and not placeregex.

Thanks, as I understood I need to put it in my vscode service right?

- traefik.http.middlewares.add-context.redirectregex.regex=^https:\\/\\/([^\\/]+)\\/?$$
- traefik.http.middlewares.add-context.redirectregex.replacement=https://$$1/vscode

Not working for me :expressionless: Maybe I do something wrong.

Yep, my finnaly path in home assistant is ha.domain.com/vscode, but vscode get this own subdomain vsc..

I am pursuing goals:

  1. save its own domain vsc.domain.com
  2. add a prefix to my first service ha.domain.com - where vscode will be available