我正在尝试使用 WSGI 部署在 Apache 上部署 Django(位于 virtualenv 中)。我正在遵循https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/的默认教程
wsgi.py(Django 生成的默认文件,已删除注释):
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "server.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
apache2.conf (它与 Debian 中的 httpd.conf 相同)。将此附加到末尾:
WSGIScriptAlias / /home/user/Desktop/expofit/expofit_hg/py/server/server/wsgi.py
WSGIDaemonProcess example.com python-path=/home/user/Desktop/expofit/expofit_hg/py/server:/home/user/Desktop/expofit/expofit_env/lib/python2.7/site-packages
WSGIProcessGroup example.com
<Directory /home/user/Desktop/expofit/expofit_hg/py/server/server>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
Alias /static/ /home/user/Desktop/expofit/expofit_hg/py/server/server/static
<Directory /home/user/Desktop/expofit/expofit_hg/py/server/server/static>
Order deny,allow
Allow from all
</Directory>
但是,这以错误结束:
[Thu Dec 06 17:08:40 2012] [error] [client 192.168.56.1] ImportError: No module named django.core.wsgi
似乎标准的python是可以访问的,因为
import os
不会产生错误。所以似乎从 virtualenv 导入的模块是不可导入的。教程说:
如果您使用守护程序模式,则需要对上述配置进行进一步更改,即您不能使用 WSGIPythonPath;相反,您应该使用 WSGIDaemonProcess 的 python-path 选项,例如:
WSGIDaemonProcess example.com python-path=/path/to/mysite.com:/path/to/venv/lib/python2.7/site-packages
WSGIProcessGroup example.com
我错过了什么?