TIL that empty headers result in 400 error in Nginx
2025-02-19 • 1 min

When a request is sent with empty headers, (specifically User-Agent, Accept and Host) it causes a 400 Bad Request error from Nginx.

$ curl -H 'User-Agent:' -H 'Accept:' -H 'Host:' https://example.com
A server MUST respond with a 400 (Bad Request) status code to any HTTP/1.1 request message that lacks a Host header field and to any request message that contains more than one Host header field line or a Host header field with an invalid field value.

This behaviour can lead to some problems when dealing with healthchecks from custom load balancers that do not send any Host headers in their request.

Edited: 2025-02-19