简体   繁体   中英

uwsgi fails to serve Django from a .ini file

Steps to reproduce:

mkdir django-uwsgi
cd django-uwsgi
python -m venv venv
source venv/bin/activate
pip install Django uwsgi
django-admin startproject mysite
cd mysite
python manage.py migrate

Try to serve django locally with uwsgi via command line:

uwsgi --module mysite.wsgi --http :8000

Result: it works! YES!

Now, create a uwsgi.ini file with the following content:

[uwsgi]
module                = mysite.wsgi
http                  = :8000

then use uwsgi --ini uwsgi.ini

Result

ModuleNotFoundError: No module named 'mysite.wsgi # define the django module to use'

OK... So we need something else...

Try adding the current directory...

chdir                 = {WORKSPACE}/django-uwsgi/mysite

YES? Result:

ModuleNotFoundError: No module named 'mysite.wsgi # define the django module to use'

Try specifying the virtualenv. Result:

virtualenv            = {WORKSPACE}/django-uwsgi/venv
# or, or both
home                  = {WORKSPACE}/django-uwsgi/venv

YES? Result:

ModuleNotFoundError: No module named 'mysite.wsgi # define the django module to use'

Here is a full tracebakc:

$ uwsgi --ini uwsgi.ini 
[uWSGI] getting INI configuration from uwsgi.ini
*** Starting uWSGI 2.0.19.1 (64bit) on [Fri Jul 16 14:44:03 2021] ***
compiled with version: 9.3.0 on 16 July 2021 18:42:33
os: Linux-5.11.0-7614-generic #15~1622578982~20.04~383c0a9-Ubuntu SMP Wed Jun 2 00:57:14 UTC 2
nodename: pop-os
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 8
current working directory: /home/loicgasser/Workspace/django-uwsgi/mysite
detected binary path: /home/loicgasser/Workspace/django-uwsgi/venv/bin/uwsgi
chdir() to /home/loicgasser/Workspace/django-uwsgi/mysite
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 126880
your memory page size is 4096 bytes
detected max file descriptor number: 8192
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on :8010 # expose uWSGI directly to the public, change to http-socket when we'll use nginx fd 4
spawned uWSGI http 1 (pid: 756173)
uwsgi socket 0 bound to TCP address 127.0.0.1:46441 (port auto-assigned) fd 3
Python version: 3.8.3 (default, Feb 22 2021, 17:48:15)  [GCC 9.3.0]
PEP 405 virtualenv detected: /home/loicgasser/Workspace/django-uwsgi/venv
Set PythonHome to /home/loicgasser/Workspace/django-uwsgi/venv
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x55cc5de2c3a0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72920 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
ModuleNotFoundError: No module named 'mysite.wsgi # define the django module to use'
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 756172, cores: 1)

Note that I use pyenv:

lrwxrwxrwx 1 loicgasser loicgasser       49 Jul 16 14:41 python -> /home/loicgasser/.pyenv/versions/3.8.3/bin/python
lrwxrwxrwx 1 loicgasser loicgasser        6 Jul 16 14:41 python3 -> python

I have been stuck for a while now... Any help would be appreciated.

Here is the configuration which is working for me. The chdir should be the directory where manage.py exists so that when you mention wsgi-file it goes to the file from that path on. also provide complete path to your virtualenv

[uwsgi]
http  = 0.0.0.0:9999
virtualenv =/path/to/djangapp/env
chdir = /path/to/djangapp -- this is where manage.py exists
wsgi-file = djangapp/wsgi.py --wsgi file path from above path
processes = 4
threads = 2
vacuum = True
harakiri=20
stats = 0.0.0.0:8000
daemonize = /path/to/djangapp/logs/CustomerCare-@(exec://date +%%Y-%%m-%%d).log
log-reopen = true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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