HAProxy Server DOWN: Check "Layer7 wrong status"
Reproduce the reasons HAProxy logs when it marks a server DOWN, tell them apart, then fix a health endpoint that returns 404 or 301, and tune inter, fall, rise.
Server app/s1 is DOWN, reason: Layer7 wrong status, code: 404 — the server is running, but HAProxy has taken it out. Read the text after reason: before you touch the config. The logs below come from HAProxy 2.8.16 on port 18641 with four backend servers, each broken a different way. The leading +0.3s is time since start, and long lines are cut with …. The 503 that follows once every server is out is in this article; the SC-- in the log is explained in this one.
[1] Read reason: in the DOWN log. /health returns 404 on s1 and 301 on s2, nothing listens on the port of s3, and s4 is an address that never answers.
+ 0.3s Server app/s1 is DOWN, reason: Layer7 wrong status, code: 404, info: "Not Found", check duration: 9ms. 3 active and 0 backup servers left. …+ 0.8s Server app/s2 is DOWN, reason: Layer7 wrong status, code: 301, info: "Moved Permanently", check duration: 1ms. 2 active and 0 backup servers left. …+ 1.2s Server app/s3 is DOWN, reason: Layer4 connection problem, info: "Connection refused", check duration: 0ms. 1 active and 0 backup servers left. …+ 3.8s Server app/s4 is DOWN, reason: Layer4 timeout, check duration: 2003ms. 0 active and 0 backup servers left. …+ 3.8s backend app has no server available![2] Sort the reason by layer. Layer4 is the TCP connection; Layer7 is the HTTP response.
| Reason | Meaning | Look at |
|---|---|---|
Layer4 connection problem | Connection refused and similar | Is the backend listening there? ss -tlnp |
Layer4 timeout | No answer to the connection | Address, routing, firewall |
Layer7 wrong status | A response came, but the status code was not the expected one | The code: value, steps 4–5 |
Layer7 timeout | Connected, but no response within timeout check | A slow health handler |
Layer7 timeout was produced by a /health that answers after 5 seconds with timeout check 1s; the log showed check duration: 1001ms.
[3] Check the current state with show stat on the runtime API (the global section needs a stats socket). Cut the status, check_status and check_code columns listed in section 9.1 (CSV format) of the management manual.
# echo "show stat" | socat stdio /run/haproxy/admin.sock | cut -d, -f1,2,18,37,38# pxname,svname,status,check_status,check_codeapp,s1,DOWN,L7STS,404app,s2,DOWN,L7STS,301app,s3,DOWN,L4CON,app,s4,DOWN,* L4TOUT,L7STS, L4CON and L4TOUT pair with Layer7 wrong status, Layer4 connection problem and Layer4 timeout in the log. The manual's table does not explain the * on the last server, so this article does not guess what it means.
[4] Find the request the check sends, then send the same one with curl. With only option httpchk, the manual's defaults are method OPTIONS, URI / and version HTTP/1.0. http-check send changes the request.
backend app option httpchk http-check send meth GET uri /health ver HTTP/1.1 hdr Host example.com http-check expect status 200 server s1 192.0.2.10:8080 check inter 2s fall 3 rise 2$ curl -si -H 'Host: example.com' http://192.0.2.10:8080/health | head -1HTTP/1.1 404 Not Found[5] Match the status code. According to the manual, a check with no http-check expect accepts any 2xx or 3xx. That is why the status 200 above turned a 301 into Layer7 wrong status. Delete that one line, keep s1 on 404 and s2 on 301, and only s1 goes DOWN.
+ 0.1s Server app/s1 is DOWN, reason: Layer7 wrong status, code: 404, info: "Not Found", check duration: 1ms. 1 active and 0 backup servers left. …If the 301 is legitimate, allow it with http-check expect status 200,301; otherwise point uri at the redirect target. A 404 fails under the default rule too, so first check that the app actually has /health.
[6] inter (check interval, default 2000ms), fall (consecutive failures before DOWN, default 3) and rise (consecutive successes before UP, default 2) set the speed. Two servers with different values, with /health switched 200 → 404 → 200:
server slow 192.0.2.10:8080 check inter 2s fall 3 rise 2 server fast 192.0.2.10:8081 check inter 500ms fall 2 rise 1+ 5.0s ## mode -> 404+ 5.6s Server app/fast is DOWN, reason: Layer7 wrong status, code: 404, …+ 10.1s Server app/slow is DOWN, reason: Layer7 wrong status, code: 404, …+ 15.0s ## mode -> 200+ 15.2s Server app/fast is UP, reason: Layer7 check passed, code: 200, …+ 18.1s Server app/slow is UP, reason: Layer7 check passed, code: 200, …The ## mode lines were written by the test script at the moment it changed the status. DOWN took 0.6 s on fast and 5.1 s on slow; recovery took 0.2 s and 3.1 s. Smaller values pull a server out and put it back faster, at the cost of flapping on a brief failure.
[7] After the fix, validate the config and reload. When the server recovers, an is UP line appears and requests reach it again.
# haproxy -c -f /etc/haproxy/haproxy.cfgConfiguration file is valid# systemctl reload haproxy+ 14.3s Server app/s1 is UP, reason: Layer7 check passed, code: 200, check duration: 1ms. 1 active and 0 backup servers online. 0 sessions requeued, 0 total in queue.+ 20.0s 203.0.113.7:44076 [19/Oct/2026:12:58:04.869] web app/s1 0/0/0/1/1 200 117 - - ---- 1/1/0/0/0 0/0 "GET / HTTP/1.1"Analyze your HAProxy log in the browser ↗ — nothing is uploaded.