错误502 upstream sent too big header
Posted 学习也休闲
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了错误502 upstream sent too big header相关的知识,希望对你有一定的参考价值。
nginx log 错误502 upstream sent too big header while reading response header from upstream
cookies的值超出了范围我是说
看看了一下日志
错误502 upstream sent too big header while reading response header from upstream
sudo gedit /var/log/nginx/error.log
查看错误日志
upstream sent too big header while reading response header from upstream
你去搜这个错误,网上的解释都差不多,无外乎是cookie携带的header太多了,让你设置:
fastcgi_buffer_size 128k;
fastcgi_buffers 8 128k;
逐步尝试。其中fastcgi_buffers 8 128k 这句,fastcgi_buffers 32 32k 这样更好,内存是整块分配和释放的,减少单位k数能尽可能利用。
另外,如果你用nginx做负载均衡的话,改了上述参数是没用的,要在转发的配置上,比如以下设置:
location @to_other {
proxy_buffer_size 128k;
proxy_buffers 32 32k;
proxy_busy_buffers_size 128k;
add_header X-Static transfer;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://backend; #请求转发
}
加粗的三行才会起作用。
fastcgi_* 可以理解成nginx接受client请求时的响应使用的。proxy是nginx作为client转发时使用的,如果header过大,超出了默认的1k,就会引发上述的upstream sent too big header。
可以参考:
http://wiki.nginx.org/NginxHttpProxyModule
http://blog.sina.com.cn/s/blog_5dc960cd0100i4mt.html
其它搜索结果可以无视,都是大同小异的。
location ~ \\.php$ {
fastcgi_buffer_size 128k;
fastcgi_buffers 32 32k;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /host/web/$fastcgi_script_name;
}
以上是关于错误502 upstream sent too big header的主要内容,如果未能解决你的问题,请参考以下文章
修复Nginx 502错误:upstream sent too big header while reading response header from upstream
修复Nginx报错:upstream sent too big header while reading response header from upstream
如何调试“FastCGI sent in stderr: Primary script unknown while reading response header from upstream”并找到实
Nginx - upstream sent invalid chunked response while reading upstream 异常问题
压测引起的 nginx报错 502 no live upstreams while connecting to upstream解决