HTTP vs TCP
Recap
Let's review the configuration from the previous lesson:
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.
💡 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) traffictcp– for handling Layer 4 (transport-level) traffic
💡 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
- Previous lesson
- Your First Load Balancer
- Next lesson
- Load Balancing Algorithms