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

2024-03-29 08:07:58 发布

您现在位置:Python中文网/ 问答频道 /正文

复制步骤:

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]
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'

以下是完整的回溯:

$ 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

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


Tags: thetodjangohttpwsgihomevenvis
1条回答
网友
1楼 · 发布于 2024-03-29 08:07:58

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

相关问题 更多 >