The problem for me was that there was an earlier server {}
block (the default one, actually). By earlier, I mean it comes first when doing nginx -T
. Nginx "shouldn't" have matched it, but it did, and nginx was using its configuration, which did not specify any of the directives regarding header length, such as large_client_header_buffers
. Why was it used? According to this github comment that's for an add-on nginx headers module:
nginx throws out 414 very early, during reading and parsing the request header's first line. Because it happens so early, no location is matched against the current (guilty) request yet while your more_set_headers directive is a "location configuration" which only takes effect for a request that has already been associated with a location {} block
Solutions:
Do 1 of these 3 things:
- Put directives related to request header size in the EARLIER
server {}
block. It probably needs to go in the earliest one.
- Remove the EARLIER
server {}
block
- Delete the EARLIER config file
Example problem configs
#/etc/nginx/conf.d/default.conf
server {
# Note: even if this block were completely empty, it'd be the same problem!
listen 80;
server_name localhost;
}
#/etc/nginx/conf.d/mysite
server {
listen 80;
server_name mysite.test;
large_client_header_buffers 4 64k;
}
How to fix
#/etc/nginx/conf.d/default.conf
server {
# put your request header size directives in here, or remove this file
client_header_buffer_size 5120k;
large_client_header_buffers 16 5120k;
}
#/etc/nginx/conf.d/mysite
server {
listen 80;
server_name mysite.test;
# no need for large_client_header_buffers here
}