Created Monday 11 November 2024
Just to test which HAProxy you are actually hitting, you can set up a backend to just dish out a small text file.
REF: https://webmasters.stackexchange.com/questions/109942/haproxy-as-web-server
The accepted answer of "no, it is not designed to do that" is correct.
But software being what it is, if you DO still want to do it, there is a hacky workaround.
You need an ACL pointing the request to a custom backend. For this example lets say you wanted to serve robots.txt
frontend port80
use_backend robots if is_robotstxt
errorfile 503 /etc/haproxy/errors/robots.http
So in that file, we put
Cache-Control: no-cache
Connection: close
Content-Type: text/plain
so now what should be a 503 error is actually a 200 Found reply, content and all.
Note that doing this is not really recommended and comes with many limitations. Most obvious is that you can only serve one file this way per backend. Less obvious is that this file must fit inside haproxy's BUFSIZE, which is usually 8 or 16kB. Haproxy also is not doing any kind of sanitization on the file served this way, so its on you to serve the right headers the right way. If your clients need \r\n instead of just \n, thats on you to handle.
You're much better off just setting up a copy of your webserver of choice and just having a "static asset backend" haproxy can route to.