Traefik with Front & Api

Hello to all,

I want to use Traefik as a reverse proxy for my 3 part application:

  • A frontend in VueJs (Apache HTTPD)
  • A backend in java spring (tomcat)
  • a Keycloak Iam

My domain name (this is an example) is toto.com.

I want toto.com :

Is this configuration possible? For the moment I use 3 different subdomains (toto.com, api.toto.com & auth.toto.com) but it's not optimak

Here is a sample configuration that should suit your needs:

version: '3.6'

services:
  traefik:
    image: traefik:v2.6
    command:
      - --providers.docker
    ports:
      - "80:80"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

  frontend:
    image: traefik/whoami
    command: -name frontend
    labels:
      traefik.http.routers.frontend.rule: Host(`localhost`)

  backend:
    image: traefik/whoami
    command: -name backend
    labels:
      traefik.http.routers.backend.rule: Host(`localhost`) && PathPrefix(`/api`)

  keycloak:
    image: traefik/whoami
    command: -name keycloak
    labels:
      traefik.http.routers.keycloack.rule: Host(`localhost`) && PathPrefix(`/auth`)

Here's what you get:

> curl localhost | grep Name
Name: frontend
> curl localhost/api | jq .name
"backend"
> curl localhost/auth | grep Name
Name: keycloak

All of these is doable thanks to the default priority on routers.

Hope it helps

1 Like

Hi it doesnt works for me

backend:
     container_name: Backend
     image: JavaBack
     volumes:
       - ./application.yml:/usr/local/lib/application.yml
     labels:
       - "traefik.enable=true"
       - "traefik.http.routers.toto-back.rule=Host(`app.toto.xyz`) && PathPrefix(`/api`)"
		[...]
       - "com.centurylinklabs.watchtower.enable=false"


   frontend:
     container_name: Frontend
     image: httpd:alpine
     networks:
       - public
     volumes:
       - ./Front/frontend/dist:/usr/local/apache2/htdocs/
     labels:
       - "traefik.enable=true"
       - "traefik.http.routers.toto-front.rule=Host(`app.toto.xyz`)"
	   [...]

But

image

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.