I've got a default nginx config (I don't explicitly return 400
for any scenario):
http {
...
include /etc/nginx/mime.types;
default_type application/octet-stream;
...
include /etc/nginx/conf.d/*.conf;
}
and it returns
<html>
<head><title>400 Request Header Or Cookie Too Large</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<center>Request Header Or Cookie Too Large</center>
<hr><center>nginx</center>
</body>
</html>
* Closing connection 0
which is OK.
However I'd like to alter nginx config to return 431
instead of 400
for that kind of error, what's the easiest way to do it?
I tried looking at the following questions:
- nginx 431 Request Header Fields Too Large
- 400 Bad Request Request Header Or Cookie Too Large nginx
- nginx 431 Request Header Fields Too Large
but they're more about fixing the error instead of returning a different status code.
The alternative solution could be to bump the limit:
server {
# ...
large_client_header_buffers 4 32k;
# ...
}
by following https://stackoverflow.com/a/19285146/17109505.
I also found a config that do map $status $status_text {
under http
block:
map $status $status_text {
...
431 'Request Header Fields Too Large';
...
}
will it be able to fix that?