2014-02-28 33 views
20

我現在總是在詢問我的用戶在做......這通常會返回872行,並採取2.07運行中得到一個502 MySQL的。但是它返回了大量的信息。 (每一行都包含很多東西)。有任何想法嗎?錯誤:上游過早關閉的連接從上游讀取響應頭[uWSGI/Django的/ NGINX]

運行的Django(tastypie REST API),Nginx的和uWSGI棧。

服務器配置與NGINX

# the upstream component nginx needs to connect to 
upstream django { 
    server unix:///srv/www/poka/app/poka/nginx/poka.sock; # for a file socket 
} 

# configuration of the server 
server { 
    # the port your site will be served on 
    listen 443; 


    # the domain name it will serve for 
    server_name xxxx; # substitute your machine's IP address or FQDN 
    charset  utf-8; 

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

    # Finally, send all non-media requests to the Django server. 
    location/{ 
     uwsgi_pass django; 
     include  /srv/www/poka/app/poka/nginx/uwsgi_params; # the uwsgi_params file you installed 
    } 
} 

UWSGI配置

# process-related settings 
# master 
master   = true 
# maximum number of worker processes 
processes = 2 
# the socket (use the full path to be safe 
socket   = /srv/www/poka/app/poka/nginx/poka.sock 
# ... with appropriate permissions - may be needed 
chmod-socket = 666 
# clear environment on exit 
vacuum   = true 

pidfile = /tmp/project-master.pid # create a pidfile 
harakiri = 120 # respawn processes taking more than 20 seconds 
max-requests = 5000 # respawn processes after serving 5000 requests 
daemonize = /var/log/uwsgi/poka.log # background the process & log 
log-maxsize = 10000000 
#http://uwsgi-docs.readthedocs.org/en/latest/Options.html#post-buffering 
post-buffering=1 
logto = /var/log/uwsgi/poka.log # background the process & log 
+1

明顯的答案將被分割數據或增加超時。這不行嗎? – jwalker

+0

我可以在哪裏增加超時時間?增加切腹沒有幫助。我需要真正在拆分不久的將來,數據...但我沒有時間,現在...... – abisson

+0

我認爲2.07是秒?日誌中的任何內容?直接運行uWSGI HTTP服務器以查看uWSGI或nginx是否窒息? – jwalker

回答

9

這是不太可能的nginx的配置問題。

這是幾乎可以肯定的是,後端實際上崩潰(或只是終止連接),而不是給一個格式錯誤的響應。即錯誤信息告訴你問題是什麼,但你正在尋找解決問題的地方。

你沒有提供足夠的信息,從而允許使用找出確切的問題是什麼,但如果要我猜:

which usually returns 872 rows and takes 2.07 to run in MySQL. It is however returning a LOT of information.

這是不是超時某處或運行內存。

+0

現在沒有872行......在不久的將來它可能會增長到10,000個。但用戶最終需要以這種或那種方式將這10,000行記錄到他的iPad中。我應該開始考慮批量發送數據嗎? – abisson

+4

不,您應該找到導致後端終止請求的原因。 – Danack

1

在你@django所在地塊,你可以嘗試加入一些代理讀取和連接超時屬性。例如

location @django { 
    proxy_read_timeout 300; 
    proxy_connect_timeout 300; 
    proxy_redirect off; 

    # proxy header definitions 
    ... 
    proxy_pass http://django; 
} 
6

我有同樣的問題,有什麼固定的,對我來說是增加我的域名在 settings.py如:

ALLOWED_HOSTS = ['.mydomain.com', '127.0.0.1', 'localhost'] 

通過同樣的問題,我的意思是我連加載頁面,nginx會返回一個502,而不會提供任何可能導致應用程序崩潰的頁面。

而且nginx的日誌包含:

Error: upstream prematurely closed connection while reading response header from upstream 
相關問題