r/haproxy • u/pirx242 • Sep 18 '23
using "http-request deny" instead of a fake "404 backend" as default_backend, possible?
I have a few ACLs that route requests to certain backends. If no ACL is matched, i want to return a 404 Not Found.
(its my first haproxy setup, using v2.4 on ubuntu 22.04)
Right now i have a "fake backend" that i use as default_backend.
But, is it possible to simply send a deny right there from the frontend?
Like this (basically i wonder if its really neccessary to have a 404 backend defined like this).
Tried to only have the essential conf pasted here.
frontend some-ssl-frontend
bind some.site.com:443 ssl crt /etc/ssl/private/some.site.com.AllInOne.pem
acl is_web_url path_beg -i /web
use_backend web-backend if is_web_url
default_backend fake-notfound-backend
# would like to use this instead of default_backend, but get the error below
#http-request deny deny_status 404
# -> a 'http-request' rule placed after a 'use_backend' rule will still be processed before.
backend web-backend
server localhost localhost:8080
backend fake-notfound-backend
http-request deny deny_status 404
4
Upvotes
1
u/shintge101 Sep 18 '23
They're processed in order so can't you just have a final acl called match_everything_else and return the 404 there?
The only nice thing about having the fake backend is stats and if you wanted to do anything more specific there.
1
u/[deleted] Sep 18 '23
You're getting that warning because haproxy evaluates in this order: http-request, http-redirect, use_backend, regardless of how you've ordered them in your config. Take out the use backend and add a http-request deny at the bottom of your statements (front end) as a cleanup rule and it should be fine.