我想部署Django(位於virtualenv)在Apache上使用WSGI部署。我下面從https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/Django Apache的wsgi virtualenv導入錯誤
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導入的模塊是不可導入的。 教程說:
A further change required to the above configuration if you use daemon mode is that you can't use WSGIPythonPath; instead you should use the python-path option to WSGIDaemonProcess, for example:
WSGIDaemonProcess example.com python-path=/path/to/mysite.com:/path/to/venv/lib/python2.7/site-packages
WSGIProcessGroup example.com
我缺少什麼?
做了什麼用途和教程建議。在Apache日誌中結束了:「ImportError:No module named site」。將代碼更改爲之前的版本,但日誌不斷更新,因此wsgi.py中沒有更多的「導入網站」 – TheMeaningfulEngineer
然後,您正在使用針對與虛擬環境不同的Python版本編譯的mod_wsgi,或者你填滿了你設置WSGIPythonHome的東西。因爲如果使用mod_wsgi 3.4而不是WGSIPythonHome,則使用守護進程模式,請使用WSGIDaemonProcess指令的python-home選項。 –
@GrahamDumpleton,但我沒有看到'WSGIDaemonProcess'指令中的'python-home'選項 https://code.google。com/p/modwsgi/wiki/ConfigurationDirectives#WSGIDaemonProcess – eldos