做專案時碰到富文字的內容太多,提交請求時,請求頭過長報錯,先是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;