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

时间:2021-05-22 19:20:32

I am quite new to python and am working on my first django project. I followed this tutorial. I managed to configure all the things but django app itself. It works if I run django server alone, however it does not work when started by uwsgi.

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

This is my uwsgi conf:

这是我的uwsgi conf:

import os

from django.core.wsgi import get_wsgi_application

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

application = get_wsgi_application()

And error from uwsgi log:

来自uwsgi日志的错误:

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

So I looked up for startup 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

My project's dirtree:

我的项目很糟糕:

.
|-- api
|   |-- __init__.py
|   |-- __init__.pyc
|   |-- media
|   |   `-- sample-media.jpg
|   |-- settings.py
|   |-- settings.pyc
|   |-- urls.py
|   |-- urls.pyc
|   |-- wsgi.py
|   `-- wsgi.pyc
|-- db.sqlite3
|-- manage.py
|-- static
|   `-- admin
|       ... ... ... ...
|-- uwsgi_conf.ini
`-- uwsgi_params

I hope I provided enough information, however I can tell u more - the problem is that I actually have no idea where to look.

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

Thanks in advance :)

提前致谢 :)

1 个解决方案

#1


10  

You are probably lacking a chdir line in your uwsgi_conf.ini. Or, probably, you have a chdir line, but it is wrong.

您可能在uwsgi_conf.ini中缺少chdir行。或者,可能,你有一个chdir线,但它是错误的。

This is confirmed by your traceback:

回溯证实了这一点:

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

Here you should see ./api/wsgi.py, not ./wsgi.py.

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

Clearly, the working directory of uWSGI is the api/ directory, while it should be the parent directory.

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

In general, your uWSGI configuration file should look like this:

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

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

See also the Django documentation on uWSGI.

另请参阅有关uWSGI的Django文档。

#1


10  

You are probably lacking a chdir line in your uwsgi_conf.ini. Or, probably, you have a chdir line, but it is wrong.

您可能在uwsgi_conf.ini中缺少chdir行。或者,可能,你有一个chdir线,但它是错误的。

This is confirmed by your traceback:

回溯证实了这一点:

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

Here you should see ./api/wsgi.py, not ./wsgi.py.

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

Clearly, the working directory of uWSGI is the api/ directory, while it should be the parent directory.

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

In general, your uWSGI configuration file should look like this:

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

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

See also the Django documentation on uWSGI.

另请参阅有关uWSGI的Django文档。