sendfile() 在向上游 nginx 502 发送请求时失败(32:管道损坏)

Usm*_*han 5 python django nginx uwsgi

我正在运行 Django、uwsgi、ngix 服务器。我的服务器适用于较小尺寸的 GET、POST 请求。但是在POST大尺寸的请求时,nginx返回502:nginx error.log是:

2016/03/01 13:52:19 [error] 29837#0: *1482 sendfile() failed (32: Broken pipe) while sending request to upstream, client: 175.110.112.36, server: server-ip, request: "POST /me/amptemp/ HTTP/1.1", upstream: "uwsgi://unix:///tmp/uwsgi.sock:", host: "servername"
Run Code Online (Sandbox Code Playgroud)

因此,为了找到真正的问题所在,我在不同的端口上运行 uwsgi 并检查同一请求是否发生任何错误。但是请求成功了。因此,问题出在 nginx 或 unix 套接字配置上。Ngin-x 配置:

# the upstream component nginx needs to connect to
upstream django {
     server unix:///tmp/uwsgi.sock; # for a file socket
#   server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}

# configuration of the server
server {
# the port your site will be served on
    listen      80;
# the domain name it will serve for
    server_name 52.25.29.179; # substitute your machine's IP address or FQDN
        charset     utf-8;

# max upload size
    client_max_body_size 75M;   # adjust to taste

# Django media
        location /media  {
            alias /home/usman/Projects/trequant/trequant-python/trequant/media;  # your Django project's media files - amend as required
        }

    location /static {
        alias /home/usman/Projects/trequant/trequant-python/trequant/static; # your Django project's static files - amend as required
    }

# Finally, send all non-media requests to the Django server.
    location / {

########    proxy_pass              http://127.0.0.1:8000;
########    proxy_set_header        Host             $host;
########    proxy_set_header        X-Real-IP        $remote_addr;
########    proxy_set_header        X-Forwarded-For  $proxy_add_x_forwarded_for;
        uwsgi_pass  django;
        uwsgi_read_timeout 600s;
        uwsgi_send_timeout 600s;
        include     /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
    }
}
Run Code Online (Sandbox Code Playgroud)

那么,知道我做错了什么吗?先感谢您。

ham*_*x0r 2

据说post-buffering = 8192在 uwsgi.ini 文件中进行设置可以解决此问题。我从 2.5 年前的答案得到了这个答案,这意味着这个修复不是根本原因。希望能帮助到你!