Traefik swarm worker node path :: how2 connect service/container via traefik

I need to connect the tenants of my app to the domain with /path/to/slot/ via traefik

I do have up and running:

  • docker swarm mode running

  • with dashboard & portainer & with letsencrypt certbot /ssl

  • & with the "index-login-php-lamp-app" running on the master-node. (with redis for the PHP $_SESSION vars running on a worker-node & with a sticky-flag for the defined cookie (via treafik.labels. .. defined in my compose.yml ...)

the label defined for making the connection is as follows:

  - traefik.http.routers.pathtoproject-websecure.rule=Host(`mydomain.xyz`) && Path(`/path/to/project`)

(later, I want to set the /path/to/project via env var and point to the tenant's instance that way...)

However, via:
mydomain.xyz/path/to/project/ all I get is a 404 "Apache/2.4.51 (Debian) Server at mydomain.xyz Port 80" // I think, this is the Apache running on the master and not the one of the worker, btw ...)

any ideas?

additional info:

  • the network I use /want to use for connecting the containers & services via traefik ("cloud-public" overlay network) is available on both nodes (docker network ls i same ID); BUT: network inspect ['the NETWORK ID'] shows me different results for the containers. (only those running on the node. Is this the sign of an error, or normal behavior? ) ... actually, I's expect not only to see the Peers (what I see, with the node's IPs), but all the containers connected with the network via these nodes ...

  • "Id": & "Created:" values of the network(s?) "cloud-public" are different on both nodes!
    → is this normal behavior, or a sign that I do have two different networks with the same name ?

... If you have some ideas / links with info, preferable with some comments: might be useful for me and for others (traefik & docker swarm has not too many info / examples / tutorials yet ...)


nxt try:
since I have portainer up and running via subdomain, I did deciede to stick with this design and created another subdomain and it works there - BUT only WITHOUT PATH:

    • || - traefik.http.routers.pathtoprojecttest-websecure.rule=(Host(a.mydomain.xyz))

is working fine ...
...but, when I add the path:

    • traefik.http.routers.pathtoprojecttest-websecure.rule=(Host(a.mydomain.xyz) && Path(/path))

(info: the quotation marks are cut out here ...)

→ it does not work. "404 page not found".

..I did try it with Path and with PathPrefix: not working, 404.

Result:

  1. sub.domain/index.php works

  2. sub.domain/path/index.php works not

... documentation is a bit poor here, isn't it? (there are still some older , yet unsolved questions in stack overflow with the same problem ...

working .replacepathregex. example:

(info: I am fixing the instances / tenants to specific nodes - so when one customer is "playing stupid" it's only his node which is affected ... performed via constraint of the service, btw..)

---------------- eg :: start: with dummy-path: /pathtotenant --------

  labels:
    - "traefik.enable=true"

    - traefik.http.middlewares.serviceInstance_001-redirect-websecure.redirectscheme.scheme=https
    - traefik.http.routers.serviceInstance_001-web.middlewares=serviceInstance_001-redirect-websecure
 # ---------------   
    - "traefik.http.routers.serviceInstance_001-web.rule=Host(`domain.abc`) && PathPrefix(`/pathtotenant`)"
    - "traefik.http.routers.serviceInstance_001-web.middlewares=serviceInstance_001-replacepathregex, serviceInstance_001-redirectregex" # these are the both below!
    
    - "traefik.http.middlewares.serviceInstance_001-replacepathregex.replacepathregex.regex=^/pathtotenant/(.*)"
    - "traefik.http.middlewares.serviceInstance_001-replacepathregex.replacepathregex.replacement=/$$1"
    - "traefik.http.middlewares.serviceInstance_001-redirectregex.redirectregex.regex=^(.*)/pathtotenant$$"
    - "traefik.http.middlewares.serviceInstance_001-redirectregex.redirectregex.replacement=$$1/pathtotenant/"      
 # ---------------   
    - traefik.http.routers.serviceInstance_001-web.entrypoints=web
      
    - traefik.http.routers.serviceInstance_001-web.tls.certresolver=letsencrypt
    - traefik.http.routers.serviceInstance_001-web.tls=true
    - traefik.http.routers.serviceInstance_001-web.entrypoints=websecure
    - traefik.http.services.serviceInstance_001-web.loadbalancer.server.port=80

    - traefik.http.services.serviceInstance_001-web.loadbalancer.sticky=true
    - traefik.http.services.serviceInstance_001-web.loadbalancer.sticky.cookie.name=serviceInstance001cookie
   
 # ---

    - traefik.docker.network=cloud-public

feel free to add another, perhaps better solution or "just your way of doing it" - or just add some comment & feedback!

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