Django,uwsgi和nginx - 内部服务器错误

时间:2015-05-10 17:21:31

标签: python django nginx uwsgi

我是python的新手,正在开发我的第一个django项目。我按照this教程。我设法配置所有的东西,但django应用程序本身。如果我单独运行django服务器,它会工作,但是当它由uwsgi启动时它不起作用。

这是我的uwsgi conf:

ionic serve

来自uwsgi日志的错误:

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "api.settings")

application = get_wsgi_application()

所以我查找了启动错误:

--- no python application found, check your startup logs for errors ---

我的项目很糟糕:

Traceback (most recent call last):
  File "./wsgi.py", line 16, in <module>
    application = get_wsgi_application()
  File "/var/www/api.partycon.net/virtualpy/local/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
    django.setup()
  File "/var/www/api.partycon.net/virtualpy/local/lib/python2.7/site-packages/django/__init__.py", line 17, in setup
    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
  File "/var/www/api.partycon.net/virtualpy/local/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__
    self._setup(name)
  File "/var/www/api.partycon.net/virtualpy/local/lib/python2.7/site-packages/django/conf/__init__.py", line 44, in _setup
    self._wrapped = Settings(settings_module)
  File "/var/www/api.partycon.net/virtualpy/local/lib/python2.7/site-packages/django/conf/__init__.py", line 92, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named api.settings

我希望我提供了足够的信息,但我可以告诉你更多 - 问题是我实际上不知道在哪里看。

提前致谢:)

1 个答案:

答案 0 :(得分:10)

您的chdir可能缺少uwsgi_conf.ini行。或者,您可能有chdir行,但这是错误的。

您的追溯确认了这一点:

File "./wsgi.py", line 16, in <module>

在这里,您应该看到./api/wsgi.py,而不是./wsgi.py

显然,uWSGI的工作目录是api/目录,而它应该是父目录。

通常,您的uWSGI配置文件应如下所示:

[uwsgi]
chdir=/path/to/your/project
module=mysite.wsgi:application
...

另请参阅Django documentation on uWSGI