I was able to get your configuration working using docker dynamic configuration. On traefik's stack file, I added:
labels:
- traefik.http.middlewares.errorhandler.errors.status=400-599
- traefik.http.middlewares.errorhandler.errors.service=errorhandler-backend
- traefik.http.middlewares.errorhandler.errors.query=/{status}
Note that I omit the .html part, as my error handler is a flask app, serving up a template at /{status}
I added the following to my error handler:
labels:
- traefik.enable=true
- traefik.docker.network=webgateway
- traefik.http.routers.errorhandler.rule=Host(`error.mydomain.example`)
- traefik.http.routers.errorhandler.entrypoints=websecure
- traefik.http.routers.errorhandler.tls=true
- traefik.http.routers.errorhandler.tls.certresolver=le
- traefik.http.routers.errorhandler.service=errorhandler-backend
- traefik.http.services.errorhandler-backend.loadbalancer.server.port=8000
And on an unrelated service, I added:
labels:
- traefik.http.routers.unrelated-service.middlewares=errorhandler@docker
This works if I point my browser to the url of that unrelated service and add a path that does not exist, e.g.: https://unrelated-service.mydomain.example/this/path/is/not/valid.html
The error handler's page is displayed but the url stays the same. While this works for defined services, I was hoping to have any undefined services serve up the error page. For example, if I point my browser to http(s)://does-not-exist.mydomain.example, this should deliver a 404 to the browser, since no traefik router or service is defined. I say "should" but that's what I'm trying to achieve. I'm not sure if that's possible. I figure it should be, since without any error handler defined, traefik serves up its own 404 page; just a simple 404 page not found in black and white text.