2016-03-01 2017 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;

我已經張貼此作爲一個單獨的答案,因爲無論答案可能工作,我很感興趣,看看哪些答案幫助別人最。