liukch
January 18, 2022, 2:35am
1
I use this router rule, but it does not work any more
Host(`foo.com`) && (Path(`/{id:^[A-Za-z0-9]{6}$}`) || Path(`/error/404`)) && Method(`GET`)
The /error/404
worked very well, but the path regex does not work.
But the regex itself is correct.
FlowFab
January 18, 2022, 12:34pm
2
Perhaps you can use my solution (I am on Swarm-Mode, btw) - or even better: improve it!
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:
…
working .replacepathregex. example: (via.middleware)
(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