sendfile()失败(32:Broken pipe),同时向上游nginx 502

时间:2016-03-01 14:23:36

标签: python django nginx uwsgi

我正在运行Django,uwsgi,ngix服务器。 我的服务器适用于较小尺寸的GET,POST请求。但是当POSTing大尺寸的请求时,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"

因此,为了找到真正问题的位置,我在另一个端口上运行uwsgi并检查是否在同一请求中发生任何错误。但要求是成功的。所以,问题在于nginx或unix socket配置。 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
    }
}

那么,知道我做错了什么吗?提前谢谢。

3 个答案:

答案 0 :(得分:0)

据说在你的uwsgi.ini文件中设置post-buffering = 8192将解决这个问题。我从一个2.5岁的答案here得到了这个答案,这意味着这个修复不是根本原因。希望它有所帮助!

答案 1 :(得分:0)

另一个解决方法是使用TCP socket instead of a unix socket in your conf files

  1. 在uwsgi.ini中,请在socket = 127.0.0.1:8000部分使用[uwsgi]之类的内容,而不是:

    socket = /tmp/uwsgi.sock chown-socket = nginx:nginx chmod-socket = 664

  2. 在你的nginx.conf文件中(btw在Ubuntu中,我指的是/etc/nginx/conf.d/nginx.conf,而不是简单地在{{1 }})使用/etc/nginx/代替uwsgi_pass 127.0.0.1:8000;

  3. 我已将此作为单独的答案发布,因为任何一个答案都可能有效,而且我有兴趣看看哪个答案最能帮助他人。

答案 2 :(得分:0)

就我而言,这似乎是针对会给出 308 重定向的请求。我认为我的节点后端在完全收到 postdata 之前发送了响应。更新客户端以点击新端点(无重定向)可能会永久解决我的情况。看起来很有希望。

相关问题