Python 3.5和mod_wsgi

时间:2016-08-22 22:18:49

标签: django mod-wsgi

我使用带有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()

我做错了什么?

1 个答案:

答案 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指令首先出现。