I'd like to show a custom error page instead of the "404 page not found" if one of my containers crashed or is unhealthy.
traefik:
image: "traefik:v2.0"
...
catch-all:
image: nginx:latest
networks:
- "main"
logging:
driver: json-file
volumes:
- ./error-pages/pages:/usr/share/nginx/error-pages
- ./error-pages/default.conf:/etc/nginx/conf.d/default.conf
- /etc/localtime:/etc/localtime:ro
labels:
traefik.enable: true
traefik.http.routers.error-router.rule: HostRegexp(`{host:.+}`)
traefik.http.routers.error-router.priority: 1
traefik.http.routers.error-router.entrypoints: web
traefik.http.routers.error-router.middlewares: error-pages-middleware
traefik.http.routers.error-router-secure.rule: HostRegexp(`{host:.+}`)
traefik.http.routers.error-router-secure.priority: 1
traefik.http.routers.error-router-secure.entrypoints: web-secure
traefik.http.routers.error-router-secure.middlewares: error-pages-middleware
traefik.http.middlewares.error-pages-middleware.errors.status: 400-599
traefik.http.middlewares.error-pages-middleware.errors.service: error-pages-service
traefik.http.middlewares.error-pages-middleware.errors.query: "/404.html"
traefik.http.services.error-pages-service.loadbalancer.server.port: 80
If I got a example container defined such as
services:
test:
container_name: test-web
hostname: test-web
image: nginx
ports:
- xxx:80
volumes:
- ./src:/usr/share/nginx/html
networks:
- "main"
labels:
- traefik.enable=true
- traefik.http.routers.test.rule=Host(`test.example.com`)
- traefik.http.routers.test.entrypoints=web
- traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https
- traefik.http.routers.test.middlewares=error-pages-middleware,redirect-to-https@docker
- traefik.http.routers.test-secured.rule=Host(`test.example.com`)
- traefik.http.routers.test-secured.tls=true
- traefik.http.routers.test-secured.middlewares=error-pages-middleware
- traefik.http.routers.test-secured.tls.certresolver=myhttpchallenge
it shows my custom error page thanks to the defined middleware when visiting ://example.com/does-not-exist.
When the test service is offline, I'd still get to see the error page when visiting the https://example.com page, but when using https://example.com I'm getting the plain old "404 page not found".
How to configure Traefik, so if a container was stopped I still get to see the custom error page for the web-secure entrypoint?