Django, uwsgi and nginx - Internal Server Error
You are probably lacking a chdir
line in your uwsgi_conf.ini
. Or, probably, you have a chdir
line, but it is wrong.
This is confirmed by your traceback:
File "./wsgi.py", line 16, in <module>
Here you should see ./api/wsgi.py
, not ./wsgi.py
.
Clearly, the working directory of uWSGI is the api/
directory, while it should be the parent directory.
In general, your uWSGI configuration file should look like this:
[uwsgi] chdir=/path/to/your/project module=mysite.wsgi:application ...
See also the Django documentation on uWSGI.
Žiga Patačko Koderman
Updated on June 09, 2022Comments
-
Žiga Patačko Koderman almost 2 years
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.
This is my 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:
--- 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 :)
-
Žiga Patačko Koderman almost 9 yearsOkay thanks @Andrea COrbellini. It helped me to move to the next stage: now I am getting this error in uwsgi log:
ImportError: No module named py \n unable to load app 0 (mountpoint='') (callable not found or import error)
-
Andrea Corbellini almost 9 years@ŽigaPatačkoKoderman: you have a trailing
py
somewhere. Perhaps, did you writeapi.wsgi.py
instead ofapi.wsgi
? -
Žiga Patačko Koderman almost 9 yearsThanks @Andrea Corbellini. True, i named wsgi file wsgi.py instead of api.wsgi. Thanke you very much :) and could you edit your post and add what you told me in this comments so the others can seen it easily?