I want to return a HTTP 204 error code if anyone tries to access a particular path on my web server. I could set one of my webservers to return a 204 error and point haproxy to it as a backend. However since no information is being sent, I figured this should be possible to do from haproxy itself. No need to bother my actual web servers.
I tried creating a backend that would generate the 204 error as follows:
frontend ...
...
acl is_always204 path_beg /thisone
use_backend always204 if is_always204
...
backend always204
errorfile 404 /etc/haproxy-shared/errors/204.http
The 204.http file contains:
HTTP/1.0 204 No Content
Cache-Control: no-cache
Connection: close
Content-Type: image/png
When I start haproxy, I get this error:
parsing [/etc/haproxy/haproxy:51] : status code 404 not handled, error customization will be ignored.
I think I may be going about this the wrong way. Can anyone suggest a way to force haproxy to return a 204 for a given acl match?
As mentioned in the comments, you cannot specify an errorfile for 404, as HAProxy will never generate a 404. You must use something like 503, which HAProxy does actually emit and has a configurable error file. Your 204 file can be used as is, just substitute 503 for 204 in your config.