HAProxy default route when a rule doesnt match.
-
I have HAProxy working very well directing traffic to 4 different sites. I would however like to send requests that dont match a rule to one of the sites.
For instance if you naviate to one of the following:- https://<mywanIP>
- https://somehostnamethatdoesntmatch.com
I would like for it to just be sent to done of the aforementioned 4 sites of my choosing. I've tried adding in rules to match an IP, or "not" rules, but they dont seem to be working.
-
@jaredadams
You can do this by configuring the default backend accordingly.You might already have added rules for your websites to use certain backends on match.
Add a backend and configure an 'http-request redirect' action in it. In the rule box enter
location https://<redirect-location-patch>
You may also state a redirect http code in front of the location if you want.
Set this backend as default in the frontend.
-
@viragomann hello! thanks for the reply.
I've configured a backend and on the frontend in "Default backend, access control lists and actions" section I have the default backend i want chosen.
When configuring the backend as you're indicating I'm running into problems. I can add the http-request redirect action, but it says theres no matching ACL. When I create an extremely broad ACL such as "Traffic is SSL", give it a name like "ssl_defbackend" and put that into the action's "Condition acl names" it still says it cannot match it to an ACL:
I don't think I'm doing this right.
-
@jaredadams
You did this in the backend?
I don't need to state an ACL in the backend action settings.Which package version are you on?
Mine is 0.61_7.However, I saw that I've accidentally typed a semi-colon in the URL above, which is also shown in your screenshot. I will correct that.
-
It appears I have this working, almost. If i send any web request towards the proxy that contains a hostname that doesnt match the rule it will redirect to the default backend no problem. However, i still can't get https://<ipaddress> to redirect. I get a 503.
Whats HAProxy doing differently when it sees an incoming request with an ip address rather than a hostname?
-
@jaredadams
An http frontend doesn't accept IP addresses for comprehensible reasons.
This might only work in tcp mode.