# HAProxy Configuration Error: Fix Syntax and Runtime Issues
A single configuration error can prevent HAProxy from starting or cause unpredictable runtime behavior. Understanding how to diagnose and fix these errors quickly is essential for maintaining a reliable load balancer.
Running Configuration Check
Always validate your configuration before restarting HAProxy:
haproxy -c -f /etc/haproxy/haproxy.cfgA clean configuration returns:
Configuration file is validAny errors will be displayed with file paths and line numbers.
Common Syntax Errors
Missing or Extra Braces
HAProxy uses braces to define sections. Mismatched braces cause parser errors:
[ALERT] 123/145023 (1234) : parsing [/etc/haproxy/haproxy.cfg:78]: missing '}'.Incorrect:
```haproxy frontend http_front bind *:80
acl is_static path_end .css .js use_backend static_servers if is_static
backend static_servers server s1 192.168.1.10:80 check ```
Correct:
```haproxy frontend http_front bind *:80
acl is_static path_end .css .js use_backend static_servers if is_static
backend static_servers server s1 192.168.1.10:80 check ```
Wait, that example shows correct spacing. Here's the actual error pattern:
Incorrect (missing section declaration):
```haproxy bind *:80
frontend http_front default_backend web_servers ```
Correct:
frontend http_front
bind *:80
default_backend web_serversInvalid Keyword Placement
Keywords must be in the correct section:
[ALERT] 123/145023 (1234) : parsing [/etc/haproxy/haproxy.cfg:23]: 'server' directive not allowed in 'frontend' section.Incorrect:
frontend http_front
bind *:80
server s1 192.168.1.10:80 check # Wrong! 'server' goes in backendCorrect:
```haproxy frontend http_front bind *:80 default_backend web_servers
backend web_servers server s1 192.168.1.10:80 check ```
Missing Required Parameters
Some directives require specific parameters:
[ALERT] 123/145023 (1234) : parsing [/etc/haproxy/haproxy.cfg:31]: 'bind' expects an address and optionally a port.Incorrect:
frontend http_front
bind # Missing address/portCorrect:
frontend http_front
bind *:80Another common case with server:
[ALERT] 123/145023 (1234) : parsing [/etc/haproxy/haproxy.cfg:45]: 'server' expects <name> and <address>[:<port>].Incorrect:
backend web_servers
server # Missing name and addressCorrect:
backend web_servers
server web1 192.168.1.10:80 checkQuoting Issues with Spaces
Values containing spaces must be quoted:
[ALERT] 123/145023 (1234) : parsing [/etc/haproxy/haproxy.cfg:15]: unexpected end of line in string.Incorrect:
http-request set-header X-Custom-Header This is a value with spacesCorrect:
http-request set-header X-Custom-Header "This is a value with spaces"Structural Configuration Errors
Undefined Backend References
Frontends must reference existing backends:
[ALERT] 123/145023 (1234) : parsing [/etc/haproxy/haproxy.cfg:25]: default backend 'web_servers' not found.Incorrect:
```haproxy frontend http_front bind *:80 default_backend web_servers # Backend doesn't exist
# Missing backend definition ```
Correct:
```haproxy frontend http_front bind *:80 default_backend web_servers
backend web_servers server web1 192.168.1.10:80 check ```
Duplicate Names
Server and backend names must be unique:
[ALERT] 123/145023 (1234) : parsing [/etc/haproxy/haproxy.cfg:35]: server 'web1' already exists in backend 'web_servers'.Incorrect:
backend web_servers
server web1 192.168.1.10:80 check
server web1 192.168.1.11:80 check # Duplicate name!Correct:
backend web_servers
server web1 192.168.1.10:80 check
server web2 192.168.1.11:80 checkInvalid IP Addresses and Ports
Check for typos in addresses:
[ALERT] 123/145023 (1234) : parsing [/etc/haproxy/haproxy.cfg:42]: invalid address '192.168.1.300' in 'server' directive.Incorrect:
backend web_servers
server web1 192.168.1.300:80 check # 300 is invalidCorrect:
backend web_servers
server web1 192.168.1.30:80 checkRuntime Configuration Issues
Invalid ACL Syntax
ACL conditions have specific syntax requirements:
[ALERT] 123/145023 (1234) : parsing [/etc/haproxy/haproxy.cfg:50]: error in ACL expression.Incorrect:
acl is_admin hdr(x-role) admin # String values need quotes if complexCorrect:
acl is_admin hdr(x-role) -i admin # -i for case-insensitive matchFor multiple values:
acl is_admin hdr(x-role) -i admin
acl is_editor hdr(x-role) -i editorIncorrect Timeout Values
Timeout values must use valid time units:
[ALERT] 123/145023 (1234) : parsing [/etc/haproxy/haproxy.cfg:55]: invalid timeout '10minutes'.Incorrect:
timeout client 10minutes
timeout server 10minutesCorrect:
timeout client 10m
timeout server 10mValid time units: us (microseconds), ms (milliseconds), s (seconds), m (minutes), h (hours), d (days).
Mode Mismatch
Frontend and backend modes should align:
[WARNING] 123/145023 (1234) : backend 'web_servers' has no mode set, using frontend mode 'http'.Inconsistent (works but not recommended):
```haproxy frontend http_front mode http bind *:80
backend web_servers mode tcp # TCP mode but frontend is HTTP server web1 192.168.1.10:80 check ```
Consistent (recommended):
```haproxy frontend http_front mode http bind *:80
backend web_servers mode http server web1 192.168.1.10:80 check ```
Advanced Configuration Debugging
Enable Verbose Parsing
Check what HAProxy is parsing:
haproxy -d -f /etc/haproxy/haproxy.cfgThis shows internal parsing details and can reveal subtle issues.
Validate Specific Sections
If you have multiple configuration files:
haproxy -c -f /etc/haproxy/haproxy.cfg -f /etc/haproxy/conf.d/Check Include Order
HAProxy processes includes in order. A later file can override earlier settings:
```haproxy # In main config defaults timeout client 30s
# In included file defaults timeout client 60s # This overrides! ```
Quick Verification Script
Create a script to validate and show problematic lines:
```bash #!/bin/bash CONFIG="/etc/haproxy/haproxy.cfg"
if haproxy -c -f "$CONFIG" 2>&1 | grep -q "Configuration file is valid"; then echo "Configuration is valid" else echo "Configuration errors found:" haproxy -c -f "$CONFIG" 2>&1 | grep -E "parsing|Error" fi ```
After fixing all errors, restart HAProxy:
systemctl reload haproxyUsing reload instead of restart minimizes downtime by performing a graceful restart.