首页 > 解决方案 > NGINX / Gunicorn / Flask - 上传适量数据时出现“502 Bad Gateway”和“sendfail() failed (32: Broken pipe)”

问题描述

我有一个使用 NGNIX 和 Gunicorn 托管在 Ubuntu 服务器上的 Flask API。

当发送带有少量数据的 POST 请求时,一切都很顺利。

但是,当发送的数据接近 100KB(例如一个大约 100,000 个字符的字符串)时,NGINX 会以 502 Bad Gateway 响应,并且其错误日志(/var/log/nginx/error.log)包含“sendfile() failed (32: Broken管道)同时向上游发送请求”。

“上游”是 Unix 套接字上的 Flask API。

如果将相同数量的数据分解为一系列快速连续发出的较小请求,则一切正常。发送的数据没有损坏。

此错误的可能原因是什么?

标签: apinginxflaskgunicorn

解决方案


推荐阅读