The symptom#
You add a block rule that uses a less common status code. Maybe it's 406 Not Acceptable so blocked requests are easy to tell apart from your existing 403s in the logs, or 451 for a legal block:
frontend fe_main
bind :80
http-request deny deny_status 406 if { req.hdr(user-agent) -m sub UnwantedBot }
You run a config check, or reload, and HAProxy refuses to start. In HAProxy 3.0 the alert follows this format (assembled from the source; the file, line, and proxy name are your own):
parsing [haproxy.cfg:3] : error detected in frontend 'fe_main' while parsing
'http-request deny' rule : status code '406' not handled by default with
'default-errorfiles' argument.
Fatal errors found in configuration.
The same rule with deny_status 403, 429, or 503 loads fine. The status code is a valid HTTP status, so what's wrong with it?
Why: HAProxy only has built-in pages for some codes#
When you write http-request deny with no arguments, or with only deny_status <code>, HAProxy treats it as the legacy form and quietly adds default-errorfiles. The manual says it directly: deny [deny_status <status>] is an alias of deny [status <status>] default-errorfiles. So the rule asks HAProxy to send its own built-in error page for that code.
HAProxy only has built-in error responses for a fixed set of codes, the ones it can generate itself. The HAProxy 3.0 manual lists them as 200, 400, 401, 403, 404, 405, 407, 408, 410, 413, 425, 429, 500, 501, 502, 503, and 504. The list varies a little by version. The 3.0 source also includes 421 and 422, and later releases add 414 and 431. But 406, 451, 418, and most other codes aren't in it in any release we checked, from 2.4 through the current development branch. If you ask for default-errorfiles with a code outside that list, there's no page to send, so the config is rejected.
deny_status on its own means "send HAProxy's built-in page for this code." It only works for codes that have one.Four fixes, and one that doesn't work#
1. Give the deny an inline body (recommended)
When deny has any argument beyond deny_status, HAProxy parses it with the full reply syntax that return uses. That syntax accepts any status from 200 to 599, as long as you supply a body and a content type:
http-request deny status 406 content-type text/plain string "Request blocked." if { req.hdr(user-agent) -m sub UnwantedBot }
string is a raw body. Use lf-string if you want log-format expansion, for example to tell the client which address was blocked:
http-request deny status 406 content-type text/plain lf-string "Blocked: %[src]" if { ... }
Pros: it's still a deny, so it counts toward HAProxy's denied-request counters, and you can add headers with hdr. Cons: content-type is mandatory with string/lf-string. Leave it out and you get a different validation error.
2. Use http-request return
http-request return status 406 content-type text/plain string "Request blocked." if { ... }
This accepts the same body options. Pros: it's explicit about what's being sent. Cons: HAProxy counts it as an intercepted request, not a denied one. If your dashboards or alerts read deny counters, these blocks won't show up there.
3. Send an empty response
http-request deny status 406 if { ... }
Note status, not deny_status. With no body arguments, HAProxy doesn't fall back to default-errorfiles. It sends a "dummy" response with just the status line, and any code from 200 to 599 is accepted. Pros: it's the shortest fix. Cons: clients get no body, and the difference between status and deny_status is easy to miss. Someone could "clean it up" later and bring the error back.
4. Use a body file
http-request deny status 406 content-type text/html file /etc/haproxy/pages/blocked.html if { ... }
This works like string, but the body comes from disk and is read when the config loads. lf-file is the log-format version. Pros: it's good for a branded HTML block page. Cons: it's one more file to deploy alongside the config, and the file has to fit in a buffer.
What doesn't work: errorfile 406 or an http-errors section
The natural guess is to supply the missing page yourself with errorfile 406 /path/406.http or an http-errors group. The manual's description of errorfile, errorfiles, and http-error uses the same supported-code list, though, and return's description says that with errorfile/errorfiles the status "must be one of the status code handled by HAProxy." These mechanisms replace the page for a supported code. They can't add a new one. If you want a custom page for a code like 406, use file or string on the rule itself (fixes 1 and 4).
Why one bad rule can stall every other change#
Editing one haproxy.cfg by hand, you see the error, fix the line, and move on. When the config is generated, as it is behind any control panel or automation, the failure mode is worse.
The HAProxy Data Plane API groups changes into transactions. You open one, stage any number of edits (rules, backends, servers), and commit them together. On commit, the API validates the candidate configuration by running HAProxy's own config check against it. If that check fails, the commit is rejected, and in our experience none of the staged changes land. That's usually what you want, since a half-applied config is worse than none. It also means that if your automation builds one transaction per site and sends everything at once, a single invalid rule blocks every other change in it.
It gets worse with a reconciler that keeps retrying. On every pass it rebuilds the same transaction, including the same bad rule, and fails at the same point. Certificate swaps, backend changes, and unrelated rule edits for that site all wait behind it, and nothing obvious tells you why.
Guarding against it#
- Check before you reload.
haproxy -c -f /etc/haproxy/haproxy.cfgparses the config and exits without binding: zero if valid, non-zero if not. Add-Vto print "Configuration file is valid" on success. Put this in CI for every generated config, not just hand-edited ones. - Validate each new rule kind on its own. When automation starts emitting a rule shape it hasn't emitted before (a new action, a new status code, new body syntax), test that shape alone in a throwaway config or transaction first. A failure then points at one rule instead of an entire site's config.
- Make failures loud. A transaction that fails validation over and over is a stuck deploy, not a transient error. Surface the HAProxy message itself. It names the file, the line, and the problem.
- Mind the API's quoting. If you set the reply body through the Data Plane API's rule fields rather than raw config text, check how your version writes the value. In our setup, the content field was written into the config verbatim, so a body with spaces had to be sent already wrapped in quotes.
How we hit this#
ShieldIngress lets you write custom rules that block requests by header, path, and similar fields. A common use is shutting out a crawler you don't want. We return 406 for these blocks on purpose, so in the logs a custom-rule block looks different from an IP or geo block, which return 403.
Our generator emitted that block as a bare deny deny_status 406. The first time a real rule of this type was created, for an unwanted crawler on one site, the generated config failed validation. Every rule for a site goes out in one Data Plane API transaction, so that site's whole sync started failing and retrying, and none of its other changes could land either. The fix was the inline body from fix #1: content-type text/plain plus a short "Request blocked." string. The rule now validates and the 406 still reaches the client.
If you're writing your own WAF logic and want to know what each field in a rule actually does, see Writing a WAF Rule with the Rule Builder.
Block bad traffic without hand-editing haproxy.cfg
Build Coraza/ModSecurity WAF rules in your browser with the free WAF Rule Builder, or start a free trial and add custom block rules from the ShieldIngress portal.