Why ErrorPage middleware use bad Host

Why ErrorPage middleware use bad Host ?

What did you do?

I've configured a "ErrorPage" middleware for return custom pages when an error occured on my services.
My middleware use a service named "service-errors", this service has one server "http://error.my-domain.com"

My server "error.my-domain.com" is an independant Apache webserver with a VirtualHost configured for this domain. He work correctly without Traefik.

My use case :

  • I've multiple servers on my service
  • healthcheck is enabled on my service
  • when all servers are down, healthcheck return HTTP 503
  • when i've a 503 error, I want capture this with ErrorPage middleware

What did you expect to see?

When all servers are down, I want see my custom error page from error.my-domain.com.

What did you see instead?

I see default Apache page "It work !"

After analyze with a tcpdump, in HTTP header, I see this : "Host" instead of "Host error.my-domain.com".

Output of traefik version: (What version of Traefik are you using?)

# traefik version
Version:      2.2.8
Codename:     chevrotin
Go version:   go1.14.6
Built:        2020-07-28T15:46:03Z
OS/Arch:      linux/amd64

Just for fun I searched for in traefik source code, guess what file came up? That's right, pkg\middlewares\customerrors\custom_errors.go

I also see that issue you raised was closed: https://github.com/containous/traefik/issues/7275

@ldez Reading the code, it looks like this is a legitimate issue to me, that is it looks like this host header might indeed come form that backendURL linked above. Would you mind having a look and explaining us where we went wrong? is the right host for the error pages.

The error pages don't handle the case when all servers are down: the middleware don't handle the 404 from Traefik.
To handle that you have to create a catch-all router with a low priority. is the right host for the error pages.

@ldez Can you explain why do you feel it is? The service for error page can point to an arbitrary back end, which includes external. An external back end very well might require a particular host header, like in the OP example. It seems like a valid scenario to me. (Just ignore the all servers are down part for the sake of this clarification).

Why not?

Indeed, I think that example "all servers are down" is bad. The problem is same if i can use error pages for classic use case with my error pages hosted on an external webserver.
By default, a service is queried with the "Host" header requested by the user OR with the domain name of the server (if "passHostHeader" option has the value "false")

I don't understand why this middleware would need special behavior with "Host".

@ldez : Do you have more information on this ?

Hello @gmarsay,

Following Customize Host header for Errors middleware · Issue #8267 · traefik/traefik · GitHub it is possible to use the Host value inferred from the configured errors service URL by using the PassHostHeader option.

Hope this helps!


Hi @kevinpollet ,

Good news, thx for your reply !

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