Return 中途出错时通过 nginx 的 body-POST

Return a body through nginx when there's an error mid-POST

我已经将 Nginx 服务器配置为反向代理。我POST一些数据给它,上游服务器在我全部发送之前确定数据无效。

我的上游服务器响应 400 代码和错误消息,并关闭连接。 Nginx 似乎对连接被中止感到不高兴,它没有将响应主体传回我的客户端。我在 'info' 级别看到来自 Nginx 的以下错误:

2015/08/25 15:28:49 [warn] 10#0: *103 a client request body is buffered to a temporary file /opt/nginx/var/client_body_temp/0000000002, client: 172.17.42.1, server: , request: "POST /upload HTTP/1.1", host: "localhost:8002"

2015/08/25 15:28:49 [error] 10#0: *103 readv() failed (104: Connection reset by peer) while reading upstream, client: 172.17.42.1, server: , request: "POST /whoopstrap HTTP/1.1", upstream: "http://172.17.1.250:80/upload", host: "localhost:8002"

172.17.42.1 - - [25/Aug/2015:15:28:49 +0000] "POST /upload HTTP/1.1" 400 25 "-" "curl/7.40.0”

如果我直接使用 Curl 与我的上游服务器通信,它会警告我连接在完成上传之前已关闭,但它会显示来自服务器的响应正文。

我可以让 Nginx 传递响应主体吗?在回复之前我需要接受整个上传吗?

你可能已经明白了这一点,但我还是会为后代回答。正如所建议的 here,是的,您似乎必须在上游服务器(或 "implement a proper connection teardown")中接受整个上传。

similar question 也已在 SO 上得到回答。