繁体   English   中英

uwsgi 无法从 .ini 文件为 Django 提供服务

[英]uwsgi fails to serve Django from a .ini file

重现步骤:

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

尝试通过命令行使用 uwsgi 在本地提供 django:

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

结果:有效! 是的!

现在,创建一个uwsgi.ini以下内容的uwsgi.ini文件:

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

然后使用uwsgi --ini uwsgi.ini

结果

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

好的...所以我们需要别的东西...

尝试添加当前目录...

chdir                 = {WORKSPACE}/django-uwsgi/mysite

是的? 结果:

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

尝试指定 virtualenv。 结果:

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

是的? 结果:

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

这是一个完整的 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)

请注意,我使用 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

我已经被困了一段时间......任何帮助将不胜感激。

这是对我有用的配置。 chdir 应该是 manage.py 所在的目录,以便当您提到 wsgi-file 时,它​​会从该路径转到该文件。 还提供您的 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

暂无
暂无

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

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