我跑步;
uwsgi --http:8091 --module proj2.wsgi
但是我遇到了以下错误;
*** Operational MODE: single process ***
Traceback (most recent call last):
File "./proj2/__init__.py", line 5, in <module>
from .celery import app as celery_app
File "./proj2/celery.py", line 5, in <module>
from celery import Celery
ImportError: No module named celery
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: 13930, cores: 1)
当我检查芹菜时,
(proj2) [proj2@localhost proj2]$ which celery
~/Env/proj2/bin/celery
奇怪的是,如果我运行带有runserver的项目,它就可以工作。
(proj2) [proj2@localhost proj2]$ python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
July 23, 2018 - 17:46:01
Django version 1.9.1, using settings 'pro.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
但是不能与uwsgi一起使用...
答案 0 :(得分:0)
终于我解决了这个问题。 我在uwsgi和nginx上提供两个项目。 使用Emperor for uwsgi管理进程。因此,应该对适当的配置进行适当的配置,以便与皇帝一起进行管理。
解决方案:
/ etc / uwsgi / sites中用于uwsgi的proj2.ini文件应如下所示。
[uwsgi]
py-autoreload = 2
project = proj2
username = proj2
base = /home/%(username)
chdir = %(base)/work/%(project)
home = %(base)/Env/%(project)
module = %(project).wsgi:application
master = true
processes = %k
uid = %(username)
socket = /run/uwsgi/%(project).sock
chown-socket = %(username):nginx
chmod-socket = 660
vacuum = true
env = DJANGO_SETTINGS_MODULE=pro.settings
logto = /var/log/uwsgi/%(project).log
项目目录下的wsgi.py应该如下:
import os
import sys
from django.core.wsgi import get_wsgi_application
sys.path.append("/home/proj2/Env/proj2/lib/python2.7/site-packages/")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "proj2.settings")
application = get_wsgi_application()
Emperor:创建uwsgi.service
Create a Systemd Unit File for uWSGI
sudo nano /etc/systemd/system/uwsgi.service
> uwsgi.service
[Unit]
Description=uWSGI Emperor service
[Service]
ExecStartPre=/usr/bin/bash -c 'mkdir -p /run/uwsgi; chown <USER>:nginx /run/uwsgi'
ExecStart=/usr/bin/uwsgi --emperor /etc/uwsgi/sites
Restart=always
KillSignal=SIGQUIT
Type=notify
NotifyAccess=all
[Install]
WantedBy=multi-user.target
因此,当您使用“ sudo systemctl start uwsgi”启动uwsgi时,所有django站点都将使用/ etc / uwsgi / sites /中的ini文件。然后Nginx将为它们提供来自/run/uwsgi/%(project).sock文件的sock文件。