2016-03-01 49 views
1

我正在运行Django,uwsgi,ngix服务器。 我的服务器对于较小尺寸的GET,POST请求正常工作。但是POST操作大尺寸的请求时,Nginx将返回502: nginx的error.log中是:sendfile()失败(32:断开的管道)同时向上游发送请求nginx 502

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套接字配置。 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 
    } 
} 

因此,任何知道我做错了吗?先谢谢你。

+0

您确定您要上传的文件低于75MB并且请求中的时间低于600秒? –

+0

是的,我正在上传3MB,是的,它不到600秒。事实上,nginx在30秒内响应502错误。 –

回答

0

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

0

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

  1. 在uwsgi.ini,在[uwsgi]部分使用类似socket = 127.0.0.1:8000代替:

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

  2. 在你nginx.conf文件(顺便说一句,在Ubuntu中,我指的是/ etc/nginx/conf.d /nginx.conf,而不是简单地在/etc/nginx/中)使用的uwsgi_pass 127.0.0.1:8000;代替include uwsgi_params;

我已经张贴此作为一个单独的答案,因为无论答案可能工作,我很感兴趣,看看哪些答案帮助别人最。

相关问题