Serving static web pages from HAProxy
I recently had to prove ownership of a web domain at work. The suggested process was easy enough: Present a web page with your company name, and a way to send a mail to an address on the given domain. We do have quite a few web services running, but I didn’t want to mess with those. However, most things we present to the internet exist behind an HAProxy pair. That’s kinda-sorta a web server, isn’t it? Could we use its standard behavior to present a web page? Sure we can!
HAProxy has a feature to present custom error messages: It’s simply a hard-coded HTTP stream, so it’s lightning fast to serve, and any browser can interpret it into a web page. Let’s build one just for kicks:
/etc/haproxy/errors/testpage.http:
So how do we present this page? Elementary: We cause an error. Not finding a backend server should trigger a 503, for example, so let’s go with that:
/etc/haproxy/haproxy.cfg:
See how the backend definition doesn’t point at any servers? Instant 503. Our load balancer is now a rudimentary web server.