使用gunicorn部署django应用程序,在gunicorn日志中部署Importerror

时间:2016-07-01 08:18:38

标签: python django ubuntu wsgi gunicorn

我正在尝试使用基于本教程的gunicorn和nginx部署django应用程序:

https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-14-04

但我很难让我的枪炮正常工作,

这是我的/etc/init/gunicorn.conf:

description "Gunicorn application server handling myproject"

start on runlevel [2345]
stop on runlevel [!2345]

respawn
setuid me
setgid www-data


exec myprojectenv/bin/gunicorn --workers 3 --bind  unix:/myproject/myproject.sock myproject.wsgi:application

在我的virtualenv中运行时:

gunicorn --bind 0.0.0.0:8000 myproject.wsgi:application
一切都好。 但是每当我开始使用gunicorn时,我的gunicorn错误日志中都会出现此错误:

ImportError: No module named 'myproject'

我检查了每个可能的选项,但没有改变。 有什么遗漏吗? 提前谢谢。

修改

我在exec之前添加了一个chdir行:

chdir /myproject/myprojectenv

我还在

ImportError: No module named 'myproject'

1 个答案:

答案 0 :(得分:1)

当您手动运行时,您可能已经在正确的目录中,因此gunicorn可以找到myproject.wsgi模块。但是当在暴发下运行时,它不会在该目录中,所以不知道在哪里找到该文件。

您可以将exec放在public override void OnActionExecuting(ActionExecutingContext filterContext) { filterContext.HttpContext.Items["timer"] = Stopwatch.StartNew(); base.OnActionExecuting(filterContext); } 行之前解决此问题。