Create error page with the provide file

Hi,

I test Traefik and I'd like to create custom page for 404 and 5xx error.

I have installed a webserver as the same host of traefik on the port 8080, I have testes with this configuration file but it's not working.

[http]
  [http.middlewares]
    [http.middlewares.500-errorpage.errors]
      status = ["500-599"]
      service = "serviceError"
      query = "/{status}.html"

      [http.middlewares.404-errorpage.errors]
        status = ["404"]
        service = "serviceError"
        query = "/{status}.html"

  [http.services]
      [http.services.serviceError.loadBalancer]
        [[http.services.serviceError.loadBalancer.servers]]
          url = "http://127.0.0.1:8080/"

Can you help me ?
Thanks

Are you running standalone or as docker container?

As a docker container see this reply:

Hi cakiwi,

Thanks, I use Traefik as standalone, not on a docker container.

Okay.

You have no routers in that config, without routers you will not trigger the middleware. The routers reference the middlewares.

Thanks cakiwi, I tried with the code bellow but is not working too :confused:

I'd like to show the page for all domain.

[http]
  [http.routers]
      [http.routers.errorPage]
          rule = "PathPrefix(`*`)"
          service = "serviceError"
          entrypoints = ["web", "websecure"]
          middlewares = ["500-errorpage", "404-errorpage"]

  [http.middlewares]
    [http.middlewares.500-errorpage.errors]
      status = ["500-599"]
      service = "serviceError"
      query = "/index.html"

      [http.middlewares.404-errorpage.errors]
        status = ["404"]
        service = "serviceError"
        query = "/index.html"

  [http.services]
      [http.services.serviceError.loadBalancer]
        [[http.services.serviceError.loadBalancer.servers]]
          url = "http://127.0.0.1:8080/"

Change you pathprefix to / that will match any url.

You are using serviceError as your router backend and your middleware ?

With PathPrefix(/) is not working, I don't understand.

If I don't add service in router on log I have this error:
the service is missing on the router" entryPointName=websecure routerName=errorPage@file

I'd like to have a error page if by exemple some people try to access to a wrong domain, do I need a default index page into the router ?

maybe what I want has no sense I don't know.
By exemple if an old DNS entry has the A record on the Traefik server I'd like to show a custom error page.

Have you got a working exemple with the file provider?

OK now is working :slight_smile: thanks you, there is the code I use:

[http]
  [http.routers]
      # http router with redirect to https
      [http.routers.errorPage]
          rule = "PathPrefix(`/`)"
          # service = "default-service"
          entrypoints = ["web", "websecure"]
          middlewares = ["502-errorpage", "5xx-errorpage", "404-errorpage"]
          priority = 1

  [http.middlewares]
    [http.middlewares.502-errorpage.errors]
      status = ["502"]
      service = "serviceError"
      query = "/{status}.html"

    [http.middlewares.5xx-errorpage.errors]
      status = ["500-501", "503-599"]
      service = "serviceError"
      query = "/5xx.html"

      [http.middlewares.404-errorpage.errors]
        status = ["404"]
        service = "serviceError"
        query = "/{status}.html"

  [http.services]
      [http.services.serviceError.loadBalancer]
        [[http.services.serviceError.loadBalancer.servers]]
          url = "http://127.0.0.1:8080/"

Hi,

Did you have to create lots of html pages ({status}.html,5xx.html or index.html) at below URL
http://127.0.0.1:8080/

On what conditions (e.g. user typing wrong URL/path in the application?) this middleware is executed?

Thanks

Thanks you for the code I was also facing same problem. Again thank you,
Regards: Home Addition Agoura Hills.

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