我使用带有virtualenv的Python 3.5,我正在尝试将其与mod_wsgi连接
Exception occurred processing WSGI script '/home/myapp/my_app/my_app/wsgi.py'.
Traceback (most recent call last):
File "/home/myapp/my_app/my_app/wsgi.py", line 12, in <module>
from django.core.wsgi import get_wsgi_application
ImportError: No module named 'django'
Apache配置:
...
DocumentRoot /home/myapp/my_app/
WSGIScriptAlias / /home/myapp/my_app/my_app/wsgi.py
WSGIDaemonProcess python-path=/home/myapp/my_app/:/home/myapp/myapp_venv/lib/python3.5/site-packages:/home/myapp
<Directory /home/myapp/my_app/ad_server>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
<Location "/">
Require all granted
</Location>
Alias /static /home/myapp/my_app/static
...
和wsgi
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_app.settings")
application = get_wsgi_application()
我做错了什么?
答案 0 :(得分:1)
您缺少WSGIDaemonProcess
的流程组名称,并且缺少相应的WSGIProcessGroup
指令或process-group
WSGIScriptAlias
选项。因此,即使具有进程组名称,WSGI应用程序也不会在守护进程组中运行,因此不了解虚拟环境。
使用:
WSGIDaemonProcess my_app python-home=/home/myapp/myapp_venv python-path=/home/myapp/my_app
WSGIScriptAlias / /home/myapp/my_app/my_app/wsgi.py process-group=my_app application-group=%{GLOBAL}
指令必须按顺序排列,因此在WSGIDaemonProcess
使用process-group
选项时,请确保WSGIScriptAlias
指令首先出现。