Bobcares

For every $500 you spend, we will provide you with a $500 credit on your account*

BLACK FRIDAY SPECIAL EXTENSION

*The maximum is $4000 in credits, Offer valid till December 6th, 2024, New Customers Only, Credit will be applied after purchase and expires after six (6) months

For every $500 you spend, we will provide you with a $500 credit on your account*

BLACK FRIDAY SPECIAL EXTENSION

*The maximum is $4000 in credits, Offer valid till December 6th, 2024, New Customers Only, Credit will be applied after purchase and expires after six (6) months

HAProxy ACL based on Hostname

by | Dec 8, 2023

Learn more about HAProxy ACL based on hostname. Our HAProxy Support team is here to help you with your questions and concerns.

HAProxy ACL based on hostname

Access Control Lists in HAProxy let us shape traffic flow based on various criteria, offering control over our application’s routing.

HAProxy ACL based on hostname

Today, we are going to take a closer look at a powerful use case of HAProxy ACLs—host-based routing.

Understanding HAProxy ACLs

HAProxy ACLs act as a set of rules defining conditions for processing incoming requests. Furthermore, these rules are key when making decisions about how to route or handle requests, providing flexibility and control over our application’s traffic.

Hostname as a Criterion

One common use of ACLs in HAProxy is routing traffic based on the hostname in the HTTP request. This is often called “host-based routing”. So, it lets us direct requests to different backend servers based on the domain requested.

Configuring ACLs for Hostname Matching

In our HAProxy configuration file, ACLs are defined using the `acl` keyword.

Furthermore, for hostname-based ACLs, the `hdr` (header) or `hdr_dom` (domain) options are used.

acl acl_example hdr(host) -i example.com

So, the ACL named `acl_example` checks if the Host header in the HTTP request matches “example.com.”

Using ACLs in Configuration

Also, after defining ACLs, we can integrate them into our backend or frontend configuration to influence routing decisions.

use_backend example_backend if acl_example

This line tells HAProxy to route traffic to the `example_backend` if the condition specified in the ACL `acl_example` is true.

Consider the following simplified HAProxy configuration demonstrating hostname-based ACLs:

HAProxy ACL based on hostname

Hence, requests with the hostname “example.com” are directed to `example_backend`, while requests with the hostname “anotherdomain.com” are directed to `another_backend`.

Wildcard Matching

HAProxy also supports wildcard matching. So, this enables us to match multiple subdomains with a single ACL. For instance:

acl is_subdomain hdr(host) -i subdomain.*

So, this ACL would match any subdomain under “subdomain.”

[Need assistance with a different issue? Our team is available 24/7.]

Conclusion

Today, our Support Engineers introduced us to HAProxy ACL based on hostname.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

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

Never again lose customers to poor
server speed! Let us help you.