2013-01-05 97 views
0

我的堆棧是uWSGI與gevent循環,瓶,mysql和python mysql.connector s我可以做異步mysql查詢。 Lateley當我運行查詢時,我在nginx日誌中得到了下面的錯誤。查詢可能需要60秒才能完成。查詢工作在堆棧的外側。當我在我的筆記本電腦上本地運行使用內置的燒錄開發服務器,並在世界各地的中間點擊mysql服務器時。所以..我假設一個nginx配置問題。Nginx的,和MySQL超時 - 上游超時(110:連接超時)

2013/01/05 01:49:48 [error] 7267#0: *2878 upstream timed out (110: Connection timed out) while reading response header from upstream, client: xxx.xxx.xxx.xxx, server: 127.0.0.1, request: "GET /ajax_grid?date_from=2013-01-02&date_to=2013-01-04&rt=crpr&a_dhx_rSeed=1357350534901 HTTP/1.1", upstream: "uwsgi://127.0.0.1:6000", host: "test.com", referrer: "http://test.com/" 

以下是我對nginx的相關選項。我應該調整以避免出現錯誤?

sendfile on; 
tcp_nopush on; 
tcp_nodelay on; 
keepalive_timeout 65; 
keepalive_requests 100000; 
types_hash_max_size 2048; 
proxy_read_timeout 200; 
reset_timedout_connection on; 
client_body_timeout 60; 
send_timeout 2; 
# server_tokens off; 
# server_names_hash_bucket_size 64; 
# server_name_in_redirect off; 

server { 
     listen 80; 
     server_name 127.0.0.1; 



    location/{ 
        include uwsgi_params; 
        uwsgi_buffering off; 
        #uwsgi_param X-Real-IP $remote_addr; 
        #uwsgi_param Host $http_host; 
        #uwsgi_pass uwsgi_dashboard; 
        uwsgi_pass 127.0.0.1:6000; 
      } 

回答

3

你可能需要設置uwsgi_read_timeout延長時間的nginx將等待來自上游服務器的數據。它的默認值是60秒。


其實,你真正需要做的是長期運行的工作轉移到後臺/異步任務,因爲大多數HTTP客戶端不願意等待數據從服務器超過120秒;無論如何,他們會超時。使用像芹菜這樣的異步處理框架,並允許客戶端查詢URL以查找正在運行的作業的狀態,可能會取消它,並在完成後檢索它。

如果您決定阻止您的wsgi容器,則可以在數據完成後使用重定向;並向客戶端發送某種內容以保持連接。

+0

Waaayyyyy真棒!!!!!!!!!!!!非常感謝。這就是訣竅! – Tampa