做项目时碰到富文本的内容太多,提交请求时,请求头过长报错,先是nginx报错,
原因是请求头的长度超出了nginx限制了,增加client_header_buffer_size和large_client_header_buffers的值,
如果nginx.conf文件不存在这两个参数,新增即可.
贴一下我的nginx.conf配置,倒数两行就是需要增加的参数.
user root;
worker_processes 2;
pid /var/run/nginx.pid;
events {
worker_connections 4096;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
gzip_disable "msie6";
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 16k;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript
image/jpeg image/gif image/png image/bmp image/x-icon;
client_header_buffer_size 512k;
large_client_header_buffers 4 512k;
include /usr/local/nginx/tomcat*.conf;
}
配置完nginx.conf重启后,没有继续报错Request-URI Too Large错误了,但是看请求没有响应,查看了下tomcat的日志,发现报错java.lang.IllegalArgumentException: Request header is too large
,网上查了下,是请求头超出了tomcat默认的head大小,处理办法:在server.xml中增加maxHttpHeaderSize
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" maxPostSize="0" maxHttpHeaderSize ="102400"/>
但是加完还是报相同的错,于是maxHttpHeaderSize又加了两个0,就解决了,客户上传的文档太大了,大家根据自己的需求调整tomcat和nginx的参数大小.
后面使用nginx上传图片时,提示413 Request Entity Too Large 错误
解决办法: 在nginx设置文件上传最大大小为2MB, 根据实际情况调整
client_max_body_size 2m;