Lesson  in  DEV: HAProxy Load Balancing Basics

HTTP vs TCP

Learn how HAProxy handles different protocols

Recap

Let's review the configuration from the previous lesson:

/etc/haproxy/loadbalancer.cfg
listen my_lb
  bind :80

  server backend-01 backend-01:80
  server backend-02 backend-02:80
  server backend-03 backend-03:80

Notice anything missing?

Hint

How does HAProxy know what kind of traffic it's routing?

Default configuration

The haproxy package installed from the package repository includes a default configuration file at /etc/haproxy/haproxy.cfg, which defines a number of default settings.

Note

💡 Other distributions may have different defaults or no defaults at all.

For example: the official container image doesn't include a default configuration file at all.

Let's take a look at those defaults:

grep -A 100 defaults /etc/haproxy/haproxy.cfg

You should see something like this:

defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        timeout connect 5000
        timeout client  50000
        timeout server  50000

        # ...

Most of the default settings aren’t relevant for now. The key directive to focus on is mode.

The mode directive tells HAProxy how to handle incoming traffic by specifying the protocol type.

The two supported values are:

  • http – for handling Layer 7 (application-level) traffic
  • tcp – for handling Layer 4 (transport-level) traffic
Note

💡 Technically, HAProxy supports additional modes, but these aren't actual network protocols and aren't relevant for load balancing use cases.

As you can see from the above configuration, HAProxy treats everything as HTTP traffic by default.

Another relevant line in the default configuration is option httplog. This tells HAProxy to include detailed HTTP request information in its access logs.

Let's remove these two lines from the configuration:

sudo sed -i '/\s*mode.*/d; /\s*option\s*httplog$/d' /etc/haproxy/haproxy.cfg

Verify that they have indeed been removed:

grep -A 100 defaults /etc/haproxy/haproxy.cfg

Restart the service for the changes to take effect:

sudo systemctl restart haproxy

References

New configuration options introduced in this lesson:

Previous lesson
Your First Load Balancer
Content
Start
Black Friday 2026