2016-02-04 63 views
0

我有一個需要「幾分鐘」來處理的請求。當我通過Django內置的開發服務器訪問它時,這工作正常。對於長時間運行請求,nginx 502壞的網關

但是,當我從nginx/uwsgi訪問它時,我得到502壞的網關。

我試着增加nginx.conf中的超時/保持活動設置,但無效。

下面是相關的conf設置: -

#keepalive_timeout 0; 
client_body_timeout 10; 
client_header_timeout 10; 
keepalive_timeout  5 5; 
send_timeout   10; 

而且nginx的調試日誌錯誤: -

2016/02/03 17:35:33 [notice] 12654#0: nginx/1.4.2 
2016/02/03 17:35:33 [notice] 12654#0: built by gcc 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC) 
2016/02/03 17:35:33 [notice] 12654#0: OS: Linux 2.6.32-358.14.1.el6.x86_64 
2016/02/03 17:35:33 [notice] 12654#0: getrlimit(RLIMIT_NOFILE): 1024:4096 
2016/02/03 17:35:33 [notice] 12655#0: start worker processes 
2016/02/03 17:35:33 [notice] 12655#0: start worker process 12657 
2016/02/03 17:35:33 [notice] 12655#0: start worker process 12658 
2016/02/03 17:35:33 [notice] 12655#0: start worker process 12659 
2016/02/03 17:35:33 [notice] 12655#0: start worker process 12660 
2016/02/03 17:36:36 [error] 12658#0: *12 upstream prematurely closed connection while reading response header from upstream, client: xxx.xxx.xxx.xxx, server: xxxxxxxx.in, request: "GET /long/url/with?request=params HTTP/1.1", upstream: "uwsgi://10.176.6.247:8001", host: "xxx.xxx.xxx.xxx" 
+2

您不應該在線執行長時間運行的任務。卸載他們到生活芹菜。 –

+0

@DanielRoseman你甚至不需要使用芹菜。 uWSGI有一個內置的假脫機程序。 http://uwsgi-docs.readthedocs.org/en/latest/Spooler.html –

回答

3

由於錯誤說upstream prematurely closed connection,這意味着它是超時的應用服務器。因此,你需要增加你的應用程序服務器的腳本執行超時設置,即:

#uwsgi.ini 
[uwsgi] 
harakiri = 200 

但是,你增加applictation服務器超時後,Nginx的代理超時可能會變得過低的是,然後修改NGIX超時太,即:

proxy_connect_timeout 120s; 
proxy_read_timeout 200s; 

uwsgi_read_timeout 200s; 
uwsgi_send_timeout 200s; 

但在一般情況下,已經在評論中提到,在相同的工藝使得長時間運行的任務,即PA不建議Django使用該請求。