I want to serve a static file like errorfile
when the response status is 500. I have to use this config in the backend section.
Asked
Active
Viewed 1,388 times
0

peeyush pathak
- 101
- 2
1 Answers
2
I've checked the HAProxy documentation but could not immediately find a configuration setting for this. But why do you want HAProxy to catch this error and return a custom HTML page? Your backend web server allows having custom error pages for code 404 and 500.
Edit: So I checked the documentation a bit more and although I haven't tested it (yet), we can perhaps try the following code in the frontend/listen/backend statement:
acl error_codes -m beg "HTTP/1.0 500"
acl error_codes -m beg "HTTP/1.0 404"
http-response allow redirect location http://example.com/errors/404.html if error_codes

Tommiie
- 5,627
- 2
- 12
- 46
-
I want to have the same error response in all the cases. servers might return a different response. – peeyush pathak Aug 22 '18 at 10:21
-
Servers might also return different web pages. The same way you sync your website across all servers, you can also sync the error pages across all webservers. – Tommiie Aug 22 '18 at 10:24
-
there are some servers that I cannot sync with(3rd part servers). – peeyush pathak Aug 22 '18 at 10:43
-
So your load balancer balances traffic with X servers, a small portion of which are third-party servers. But they must host the same web content? Then how do you sync the web content? – Tommiie Aug 22 '18 at 10:47
-
I use it more as a proxy than load balancing. – peeyush pathak Aug 22 '18 at 10:51
-
Okay, I edited my response. – Tommiie Aug 22 '18 at 12:10
-
but this will return 3** status and I do not want an extra request – peeyush pathak Aug 22 '18 at 14:16
-
Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/82072/discussion-between-tom-and-peeyush-pathak). – Tommiie Aug 22 '18 at 14:19