最近做项目,遇到一个问题,后台导出表格时,当条数超过一定数量时,会报:431 Request Header Fields Too Large的问题,然后就在网上搜索这个问题,本质的问题就是http请求header过大。
这个问题网上的解决方案基本一致,就是修改服务器的header的大小。方案如下:
在springboot项目中,在yml文件中,如下添加:
server: port: 8090 tomcat: max-swallow-size: -1 max-http-header-size: 2MB
需要说明的是,max-http-header-size是在server下,不是tomcat下。
网上很多人这样修改后都成功了,我的照样报这个错误。然后我分析了一下,既然是服务器的问题,我用的是前后端分离,请求首先到达的是ngnix,然后我又查了ngnix相关的修改,ngnix.conf的修改如下:
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
client_header_buffer_size 10240k;
large_client_header_buffers 6 10240k;
}
就是修改了client_header_buffer_size 和large_client_header_buffers 两个值。如果你的ngnix.conf中没有这个值,添加上就行。
按照这样修改,我的项目没有问题了。