Redirect traffic by a SUBPATH to different containers

Hello forum,

shortly some notice to the background of what I actually want to do:

  • I want to run a NextCloudPi server and a Gogs Git server behind a Fritz.Box on my Raspberry Pi.
  • Both are running in a Docker container.
  • Traefik should act as a reverse proxy.
  • Since I only use a DyDNS, I don't have the option to set up subdomains.
  • Therefore I am dependent on subdirectories.
  • The URL should then look something like this:
    https://huhu.spdns.de/gogs
    https://huhu.spdns.de/nxtcld

But I broke down my problem. I have found many examples but none of them really works for me.

Here is my Docker Compose File:

version: "3.3"

services:
  traefik_reverseproxy:
    container_name:  traefik_rp
    image:           traefik:v2.0
    command:
      -              --entrypoints.web.address=:80
      -              --entrypoints.websecure.address=:443
      -              --providers.docker
      -              --api.insecure
      -              --certificatesresolvers.leresolver.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory
      -              --certificatesresolvers.leresolver.acme.email=you@example.com
      -              --certificatesresolvers.leresolver.acme.storage=/acme.json
      -              --certificatesresolvers.leresolver.acme.tlschallenge=true
    ports:
      -              8080:8080
      -               443:443
      -                80:80
    volumes:
      -              /var/run/docker.sock:/var/run/docker.sock
      -              ./acme.json:/acme.json
    networks:
      -              sh_trfk

  whoami:
    image:           containous/whoami
    labels:
      -              "traefik.frontend.rule=PathPrefixStrip:/whoami"
      -              "traefik.backend=whoami"
      -              "traefik.enable=true"
      -              "traefik.passHostHeader=true"
      -              "traefik.frontend.redirect.regex=^(.*)/whoami$$"
      -              "traefik.frontend.redirect.replacement=$$1/whoami/"
      -              "traefik.frontend.rule=PathPrefix:/whoami;ReplacePathRegex: ^/whoami/(.*) /$$1"
    networks:
      -              sh_trfk

  tomcat:
    container_name:  tom
    hostname:        tom
    build:           ./dockerfiles/tom
    ports:
      -              9081:80
    labels:
      -              "traefik.http.routers.tomcat.rule=PathPrefix(`/tom`)"
      -              "traefik.http.middlewares.theTomStrip.stripprefix.prefixes=/tom"
      -              "traefik.http.routers.tomcat.middlewares=theTomStrip"
    networks:
      -              sh_trfk


networks:
  sh_trfk:

The problem with the WHOAMI container is that it doesn't work at all, although I think it would be the more correct solution.

The problem with the TOM container is that although I reach TOMCAT here, the dynamic links from Tomcat are generated incorrectly:

  • https: // localhost / tom / examples becomes https: // localhost / examples

The reason for this is clear to me, because I cut the SubPath / tom out of the URL. But how do I solve the problem?

I'm really grateful for any information, since I've been dealing with the problem for almost two weeks now.

thank you
Andreas

Hi,
this is not an exact anwer for your question but maybe it can help you.

You are saying:

Since I only use a DyDNS, I don't have the option to set up subdomains.

You can use DynDNS and Subdomains - i'm using this exact szenario.

All you nedd is a Domain Provider wich allows you to modify the nameserver and a free DNS Service that can be used for traefik DNS-Challenge to generate Wildcard Certificates like "https://www.ovh.de/".