Performing AND conditionals in HAProxy

Featured image for sharing metadata for article

Today I've been playing around with some HAProxy rules, and I wanted to only allow access to a given host if the request was to a specific route.

Trying to search for "how to write and in HAProxy" was surprisingly difficult, and odd as there was mention of it in some places, but it didn't get parsed correctly.

As it didn't seem initially straightforward, I thought I'd document that you can specify multiple conditions, and they're implicitly AND'd.

For instance:

# to route to the backend `the_host`, which is found at http://host.local
acl host_the_host hdr(host) -i host.local
acl host_the_host_allow_webhook path_beg,url_dec -i /webhook
use_backend host.local if host_the_host host_the_host_allow_webhook
                                       ^ this is implicitly an and between these two ACLs

Written by Jamie Tanna's profile image Jamie Tanna on , and last updated on .

Content for this article is shared under the terms of the Creative Commons Attribution Non Commercial Share Alike 4.0 International, and code is shared under the Apache License 2.0.

#blogumentation #haproxy.

Also on:

This post was filed under articles.

Interactions with this post

Interactions with this post

Below you can find the interactions that this page has had using WebMention.

Have you written a response to this post? Let me know the URL:

Do you not have a website set up with WebMention capabilities? You can use Comment Parade.