tarampampam / error-pages

🚧 Pretty server's error pages in the docker image & git repository (for traefik, k8s, nginx and so on)
https://tarampampam.github.io/error-pages/
MIT License
899 stars 82 forks source link

Traefik config example is not working fully as intended #311

Closed Maypul closed 2 months ago

Maypul commented 2 months ago

Is there an existing issue for this?

Describe the bug

Hello!

I have set up my instance of Traefik and ErrorPages as shown in the example in the readme but I encountered few issues.

  1. Traefik shows the ErrorPages for a while after starting up but then it goes to blank page with following error in Traefik's log: 2024-09-13T21:28:50+02:00 ERR Could not get Capture error="value not found in context" service=errorpages-svc@docker I found a workaround to add directly errorpage service to the traefik: traefik.http.routers.traefik-rtr.service: api@internal,errorpages-svc Now the pages load all the time as intended.

  2. The other services (in my case tested on Portainer), work well, the ErrorPages work well without directly putting the service in their config but they do not show the X website icon - it also gets fixed by putting errorpages-svc directly into their config.

Steps to reproduce

  1. Set up Traefik, Error Pages
  2. Check if 404 works on Traefik
  3. It works for few seconds after starting up container then at one point it shows blank page and error in the log (unless the errorpage service is specified directly in the labels)
  4. It does work on other services (in this case Portainer) but does not show the favourite icon unless errorpage service is specified directly in the labes

Configuration files

ErrorPages container:

  errorpages:
    container_name: ErrorPages
    hostname: errorpages
    image: tarampampam/error-pages:latest
    restart: unless-stopped
    networks:
      traefik:
    environment:
      TZ: $TZ
      LOG_LEVEL: info
      LOG_FORMAT: console
      LISTEN_ADDR: 0.0.0.0
      LISTEN_PORT: 8080
      ADD_TEMPLATE: 
      TEMPLATE_NAME: ghost
      DISABLE_L10N: 'true'
      DEFAULT_ERROR_PAGE: 404
      SEND_SAME_HTTP_CODE: 'false'
      SHOW_DETAILS: 'true'
      PROXY_HTTP_HEADERS: X-Request-Id,X-Trace-Id,X-Amzn-Trace-Id
      TEMPLATES_ROTATION_MODE: disabled
      READ_BUFFER_SIZE: 5120
      DISABLE_MINIFICATION: 'false'
    labels:
      traefik.enable: true
      traefik.http.routers.errorpages-rtr.entrypoints: https
      traefik.http.routers.errorpages-rtr.rule: HostRegexp(`.+`)
      traefik.http.routers.errorpages-rtr.priority: 10
      traefik.http.routers.errorpages-rtr.tls: true
      traefik.http.routers.errorpages-rtr.middlewares: middlewares-errorpages
      traefik.http.services.errorpages-svc.loadbalancer.server.port: 8080
      traefik.http.middlewares.middlewares-errorpages.errors.status: 400-599
      traefik.http.middlewares.middlewares-errorpages.errors.service: errorpages-svc
      traefik.http.middlewares.middlewares-errorpages.errors.query: /{status}.html

Traefik container:
  traefik:
    container_name: Traefik
    hostname: traefik
    image: traefik:latest
    restart: unless-stopped
    command:
      - --global.checkNewVersion=false
      - --global.sendAnonymousUsage=false
      - --ping
      - --metrics.prometheus.addrouterslabels
      - --entryPoints.http.address=:80
      - --entrypoints.http.asDefault=false
      - --entryPoints.http.http.redirections.entrypoint.to=https
      - --entryPoints.http.http.redirections.entrypoint.scheme=https
      - --entryPoints.http.http.redirections.entrypoint.permanent=true
      - --entryPoints.https.address=:443
      - --entrypoints.https.http.tls.options=tls-opts@file
      - --entrypoints.https.http.tls.domains[0].main=example.com
      - --entrypoints.https.http.tls.domains[0].sans=*.example.com
      - --entrypoints.https.http3
      - --entrypoints.https.http3.advertisedPort=443
      - --entrypoints.https.asDefault=true
      - --entryPoints.https.http.middlewares=middlewares-traefikrealip-plugin@file
      - --entrypoints.https.forwardedHeaders.trustedIPs=$CLOUDFLARE_IPS,$LOCAL_IPS
      - --entrypoints.traefik.address=:8080
      - --api=true
      - --api.dashboard=true
      - --api.insecure=false
      - --api.debug=false
      - --log=true
      - --log.format=common
      - --log.filePath=/Traefik.log
      - --log.level=ERROR
      - --accessLog=true
      - --accessLog.format=common
      - --accessLog.filePath=/Access.log
      - --accessLog.bufferingSize=100
      - --accessLog.filters.statusCodes=204-299,400-499,500-599
      - --providers.docker=true
      - --providers.docker.endpoint=tcp://socket-proxy:2375
      - --providers.docker.exposedByDefault=false
      - --providers.docker.network=traefik
      - --providers.docker.exposedByDefault=false
      - --providers.docker.defaultrule=Host(`{{ index .Labels "com.docker.compose.service" }}.example.com`)
      - --providers.file.directory=/Rules
      - --providers.file.watch=true
      - --serversTransport.insecureSkipVerify=false
      - --certificatesResolvers.dns-cloudflare.acme.email=$EMAIL_CERT
      - --certificatesresolvers.dns-cloudflare.acme.tlschallenge=false
      - --certificatesResolvers.dns-cloudflare.acme.storage=/acme.json
      - --certificatesResolvers.dns-cloudflare.acme.caServer=https://acme-v02.api.letsencrypt.org/directory
      # - --certificatesResolvers.dns-cloudflare.acme.caServer=https://acme-staging-v02.api.letsencrypt.org/directory #Staging Server
      - --certificatesResolvers.dns-cloudflare.acme.dnsChallenge.provider=cloudflare
      - --certificatesResolvers.dns-cloudflare.acme.dnsChallenge.delayBeforeCheck=90
      - --certificatesResolvers.dns-cloudflare.acme.dnsChallenge.resolvers=1.1.1.1:53,1.0.0.1:53
      - --experimental.plugins.traefik-traefikrealip-plugin.modulename=github.com/jramsgz/traefik-real-ip
      - --experimental.plugins.traefik-traefikrealip-plugin.version=v1.0.6
    networks:
      traefik:
      Socket_Proxy:
    ports:
      - target: 80
        published: 80
        protocol: tcp
        mode: host
      - target: 443
        published: 443
        protocol: tcp
        mode: host
      - target: 443
        published: 443
        protocol: udp
        mode: host
    depends_on:
      errorpages:
        condition: service_healthy
    security_opt:
      - no-new-privileges:true
    secrets:
      - source: cloudflare_api_key
        target: /run/secrets/cloudflare_api_key
      - source: cloudflare_email
        target: /run/secrets/cloudflare_email
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - $SHR_DOCKER/Traefik/acme.json:/acme.json:rw
      - $SHR_DOCKER/Traefik/Captcha:/Captcha:ro
      - $SHR_DOCKER/Traefik/Rules:/Rules:ro
      - $DIR_LOGS/Traefik/Access.log:/Access.log:rw
      - $DIR_LOGS/Traefik/Traefik.log:/Traefik.log:rw
      - $DIR_SHARED:/Shared:ro
    environment:
      TZ: $TZ
      CF_API_KEY_FILE: /run/secrets/cloudflare_api_key
      CF_API_EMAIL_FILE: /run/secrets/cloudflare_email
      DOMAIN_NAME: example.com
    labels:
      traefik.enable: true
      traefik.http.routers.traefik-rtr.entrypoints: https
      traefik.http.routers.traefik-rtr.rule: Host(`traefik.example.com`)
      traefik.http.routers.traefik-rtr.tls: true
      traefik.http.routers.traefik-rtr.service: api@internal,errorpages-svc
      traefik.http.routers.traefik-rtr.middlewares: middlewares-errorpages

Relevant log output

2024-09-13T21:29:53+02:00 ERR Could not get Capture error="value not found in context" service=errorpages-svc@docker

Anything else?

No response

Maypul commented 2 months ago

Another solution for this, was adding --metrics.addinternals=true to my Traefik instance. I do not need to specify services in each container anymore. Mentioned this on Traefik's repo with I think similar issue which was fixed for K8 (I am using Traefik in Docker).