org.apache.coyote.http11.HeadersTooLargeException: An attempt was made to write more data to the response headers than there was room available in the buffer. Increase maxHttpHeaderSize

springcloud项目,请求某个服务时报错如下:
org.apache.coyote.http11.HeadersTooLargeException: An attempt was made to write more data to the response headers than there was room available in the buffer. Increase maxHttpHeaderSize on the connector or write less data into the response headers

原因是请求头或者响应头数据太大导致,添加配置文件:

server.max-http-header-size=65546

 

注意不要使用server.tomcat.max-http-header-size。亲测有效。

解决:502 bad gateway

502 bad gateway——代理缓冲区设置过小
如果你使用的是nginx反向代理,如果header过大,超出了默认的1k,就会引发上述的upstream sent too big header (说白了就是nginx把外部请求给后端处理,后端返回的header太大,nginx处理不过来就会导致502。

server {
    listen 443;
    server_name www.api.*.com api.*.com;
    ssl on;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_certificate /etc/nginx/conf.d/4952120.com.pem;
    ssl_certificate_key /etc/nginx/conf.d/4952120.com.key;

        location / {
                proxy_pass      http://apisite;
                proxy_redirect  off;
                proxy_send_timeout 300;
                proxy_read_timeout 300;
                proxy_connect_timeout 300;

                ##添加这3行
                proxy_buffer_size 64k;
                proxy_buffers   32 32k;
                proxy_busy_buffers_size 128k;
                ##添加这3行
                
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
}

 

posted on 2021-01-12 20:18  Ruthless  阅读(3644)  评论(0编辑  收藏  举报