简体   繁体   English

在Gunicorn日志中使用Gunicorn和ImportError部署Django应用

[英]Deploying django app with gunicorn, Importerror in gunicorn log

I'm trying to deploy a django app using gunicorn and nginx based on this tutorial: 我正在尝试根据本教程使用gunicorn和nginx部署django应用程序:

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

But im having some trouble getting my gunicorn to work properly, 但是我在让我的机枪无法正常工作时遇到了一些麻烦,

This is my /etc/init/gunicorn.conf: 这是我的/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

When in my virtualenv i run: 在我的virtualenv中,我运行:

gunicorn --bind 0.0.0.0:8000 myproject.wsgi:application

everything is ok. 一切都好。 But every time i start gunicorn i get this error in my gunicorn error log: 但是每次我启动gunicorn时,都会在我的gunicorn错误日志中得到以下错误:

ImportError: No module named 'myproject'

I checked every possible option, but nothing changed. 我检查了所有可能的选项,但没有任何改变。 Is there anything im missing out? 我有什么错过吗? Thanks in advance. 提前致谢。

EDIT: 编辑:

I added a chdir line before exec: 我在exec之前添加了chdir行:

chdir /myproject/myprojectenv

Im still getting 我还在

ImportError: No module named 'myproject'

When you run this manually, you are presumably already in the correct directory, so gunicorn can find the myproject.wsgi module. 手动运行时,大概已经在正确的目录中,因此gunicorn可以找到myproject.wsgi模块。 But when running under upstart, it won't be in that directory, so will have no idea where to find the file. 但是当在新贵公司下运行时,它将不在该目录中,因此不知道在哪里可以找到该文件。

You can solve this by putting chdir /path/to/my/virtualenv before the exec line. 您可以通过将chdir /path/to/my/virtualenv放在exec行之前来解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM