Operations 5 min read

Decode HAProxy: Master Its Configuration Sections and Key Directives

This article explains the structure of HAProxy configuration files, detailing the five sections—global, defaults, frontend, backend, and listen—along with key directives such as daemon, maxconn, mode, timeouts, bind, and server, and shows how they work together to manage traffic and monitoring.

Java High-Performance Architecture
Java High-Performance Architecture
Java High-Performance Architecture
Decode HAProxy: Master Its Configuration Sections and Key Directives

HAProxy Configuration File Overview

HAProxy configuration files consist of five main sections: global, defaults, frontend, backend, and listen. Each section serves a specific purpose in defining process-level settings, default parameters, front‑end entry points, back‑end server pools, and combined front‑end/back‑end instances.

global Section

The global section contains process‑wide parameters, typically related to the operating system. Example:

global
    daemon
    maxconn 256

daemon runs HAProxy as a background service. maxconn sets the maximum concurrent connections per process.

defaults Section

Defaults define parameters inherited by subsequent sections unless overridden. Example:

defaults
    mode http
    timeout connect 5000ms
    timeout client 50000ms
    timeout server 50000ms

mode chooses between tcp (layer 4) and http (layer 7). The timeout directives specify maximum waiting times for connections, client data, and server responses.

frontend Section

The frontend declares a virtual node that receives client requests. Example:

frontend http-in
    bind *:7000
    default_backend neo4j

bind defines the listening address and port. default_backend points to the backend pool that will handle the traffic.

backend Section

The backend defines a group of real servers. Example:

backend neo4j
    server s1 127.0.0.1:8080 maxconn 32
    server s2 127.0.0.1:8081 maxconn 32

server adds a real server with a name, address, optional port, and parameters such as maxconn.

listen Section

Listen combines frontend and backend functionality, often used for administrative interfaces. Example:

listen admin
    bind *:7080
    stats enable

This creates a monitoring page on port 7080 with statistics enabled.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Operationsload balancingConfigurationnetworkHAProxy
Java High-Performance Architecture
Written by

Java High-Performance Architecture

Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.