HAProxy Redirect Unknown Subdomains


It’s possible to redirect non configured sub domains to a different error message rather than a default or error 503 which is a server side error.

Edit /etc/haproxy/haproxy.cfg and add the following to the default frontend:
default_backend no-match

Then define the no-match backend (can be done by appending to the end of the file:
backend no-match
http-request deny deny_status 400

This will return a 400 error (bad request). If another error message such as 404 is required you’ll need to create a 404.http in /etc/haproxy/errors folder and add it to the config under defaults:
errorfile 404 /etc/haproxy/errors/404.http


Simple and elegant solution to pass an error that is possibly from the user as opposed to the server.

Serve 404 from HAProxy when no acls match

About Danny

I.T software professional always studying and applying the knowledge gained and one way of doing this is to blog. Danny also has participates in a part time project called Energy@Home [http://code.google.com/p/energyathome/] for monitoring energy usage on a premise. Dedicated to I.T since studying pure Information Technology since the age of 16, Danny Tsang working in the field that he has aimed for since leaving school. View all posts by Danny → This entry was posted in Linux, Networking, Software and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *.

All comments must go through an approval and anti-spam process before appearing on the website. Please be patience and do not re-submit your comment if it does not appear.

This site uses Akismet to reduce spam. Learn how your comment data is processed.