Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sendfile() failed (32: Broken pipe) while sending request to upstream nginx 502

I am running Django, uwsgi, ngix server. My server works fine for GET, POST requests of smaller size. But when POSTing requests of large size, nginx returns 502: nginx error.log is:

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"

So, in order to find where the real problem is, I ran uwsgi on a different port and checked if any error occurs with the same request. But the request was successful. So, the problem is with nginx or unix socket configuration. Ngin-x configuration:

# 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
    }
}

So, any idea what I am doing wrong? Thank you in advance.

like image 339
Usman khan Avatar asked Oct 19 '22 14:10

Usman khan


1 Answers

Supposedly setting post-buffering = 8192 in your uwsgi.ini file will fix this. I got this answer from a 2.5-yr-old answer here and it implies this fix is not the root cause. Hope it helps!

like image 65
hamx0r Avatar answered Oct 21 '22 05:10

hamx0r