I am getting a 400 Bad Request request header or cookie too large from nginx with my Rails app. Restarting the browser fixes the issue. I am only storing a string id in my
It's just what the error says - Request Header Or Cookie Too Large
. One of your headers is really big, and nginx is rejecting it.
You're on the right track with large_client_header_buffers
. If you check the docs, you'll find it's only valid in http
or server
contexts. Bump it up to a server block and it will work.
server {
# ...
large_client_header_buffers 4 32k;
# ...
}
By the way, the default buffer number and size is 4
and 8k
, so your bad header must be the one that's over 8192 bytes. In your case, all those cookies (which combine to one header) are well over the limit. Those mixpanel cookies in particular get quite large.
In my case (Cloud Foundry / NGiNX buildpack) the reason was the directive proxy_set_header Host ...
, after removing this line nginx became stable:
http {
server {
location /your-context/ {
# remove it: # proxy_set_header Host myapp.mycfdomain.cloud;
}
}
}
With respect to answers above, but there is client_header_buffer_size
needs to be mentioned:
http {
...
client_body_buffer_size 32k;
client_header_buffer_size 8k;
large_client_header_buffers 8 64k;
...
}
Fixed by adding
server {
...
large_client_header_buffers 4 16k;
...
}