我有一個需要「幾分鐘」來處理的請求。當我通過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"
您不應該在線執行長時間運行的任務。卸載他們到生活芹菜。 –
@DanielRoseman你甚至不需要使用芹菜。 uWSGI有一個內置的假脫機程序。 http://uwsgi-docs.readthedocs.org/en/latest/Spooler.html –