Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I would like haproxy to use its own 503 document page when back server (backend) sends HTTP 503 code. Is it possible?

Have seen something like "monitor fail" conditions but don't know how to add it to the frontend.

share|improve this question
add comment

3 Answers

up vote 4 down vote accepted

You can use the errorfile directive and then a custom .http text file. So for example:

errorfile 503 /etc/haproxy/errors/503-mycustom.http

Content of the file would then be something like:

HTTP/1.0 503 Service Unavailable
Cache-Control: no-cache
Connection: close
Content-Type: text/html

<html> 
  <head>
    <title>RARRR!!!!!</title>
  </head> 
  <body style="font-family:Arial,Helvetica,sans-serif;">
    <div style="margin: 0 auto; width: 960px;"> 
          <h2 >RAWR RAWR RAWR</h2>
    </div>
  </body> 
</html>

The errorfile directive can be specific to a backend as well.

Edit:
I think I misunderstood you, you want to overwrite the the servers 503, errorfile is not for that:

It is important to understand that this keyword is not meant to rewrite errors returned by the server, but errors detected and returned by HAProxy. This is why the list of supported errors is limited to a small set.

share|improve this answer
add comment

There is something dirty you can do. You can block responses 503, which will result in returning the custom 502 error for which you can build an error page. However, keep in mind that any reason haproxy would have to return a 502 (invalid response) will return the same thing.

Basically it's as simple as "rspdeny ^HTTP/1.1 503" combined with "errorfile 502".

share|improve this answer
add comment

We have a portion of our website running on a legacy system, and I ended up using the following:

errorfile 502 /etc/haproxy/errors/502.http

acl is_internal_error status ge 500

rspideny . if is_internal_error

Hope it helps (even if it is 8 months later).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.