【发布时间】:2016-02-06 17:04:11
【问题描述】:
我有一个需要“几分钟”来处理的请求。当我通过 Django 的内置开发服务器访问它时,这工作正常。
但是,当我从 nginx/uwsgi 访问它时,我得到 502 bad gateway。
我已经尝试增加 nginx.conf 中的超时/keepalive 设置,但没有效果。
这里是相关的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 你甚至不必使用 Celery。 uWSGI 有一个内置的后台处理程序。 uwsgi-docs.readthedocs.org/en/latest/Spooler.html