1
我一直在嘗試配置mod_wsgi兩天,但仍然沒有運氣。這是我做的:在Mac OS X上配置mod_wsgi?
- 創建一個示例django項目
mysite
。運行python manage.py runserver
並確保它的工作 mysite
下創建apache
目錄,創建apache_django_wsgi.conf
,mysite.wsgi
和apache_django_wsgi.conf的空__init__.py
內容:mysite.wsgi
的WSGIPythonHome /usr/bin
WSGIRestrictStdout Off
WSGIDaemonProcess django
WSGIProcessGroup django
Alias /site_media/ "/Users/Garth/Dev/web-app/mysite/media/"
<Directory "/Users/Garth/Dev/web-app/mysite/media">
Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing
</Directory>
Alias /media/ "/Library/Python/2.6/site-packages/django/contrib/admin/media/"
<Directory "/Library/Python/2.6/site-packages/django/contrib/admin/media">
Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing
</Directory>
WSGIScriptAlias /mysite "/Users/Garth/Dev/web-app/mysite/apache/mysite.wsgi"
<Directory "/Users/Garth/Dev/web-app/mysite/apache">
Allow from all
</Directory>
內容
import os
import sys
sys.path.append('/Users/Garth/Dev/web-app/mysite')
sys.path.append('/Users/Garth/Dev/web-app')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
- 下載mod_wsgi.so(適用於Mac OS X預編譯的二進制),並把它放在/ usr/libexec目錄/ Apache2的
- 編輯/etc/apache2/httpd.conf,
地址:
LoadModule wsgi_module libexec/apache2/mod_wsgi.so
Include /Users/Garth/Dev/web-app/mysite/apache/apache_django_wsgi.conf
- 運行
sudo apachectl -k start
如果我去到localhost,我可以看到的文件和目錄列表。但如果我去localhost/mysite(這是我配置的WSGIScriptAlias),我得到了Internal Server Error
。
的apache的error_log是:
[Fri May 13 11:10:38 2011] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Fri May 13 11:10:38 2011] [notice] Digest: generating secret for digest authentication ...
[Fri May 13 11:10:38 2011] [notice] Digest: done
[Fri May 13 11:10:38 2011] [notice] Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8l DAV/2 mod_wsgi/3.3 Python/2.6.1 configured -- resuming normal operations
[Fri May 13 11:10:50 2011] [error] [client ::1] mod_wsgi (pid=10921): Target WSGI script '/Users/Garth/Dev/web-app/mysite/apache/mysite.wsgi' cannot be loaded as Python module.
[Fri May 13 11:10:50 2011] [error] [client ::1] mod_wsgi (pid=10921): Exception occurred processing WSGI script '/Users/Garth/Dev/web-app/mysite/apache/mysite.wsgi'.
[Fri May 13 11:10:50 2011] [error] Traceback (most recent call last):
[Fri May 13 11:10:50 2011] [error] File "/Users/Garth/Dev/web-app/mysite/apache/mysite.wsgi", line 1, in <module>
[Fri May 13 11:10:50 2011] [error] import os
[Fri May 13 11:10:50 2011] [error] ImportError: No module named os
有誰看到哪裏出了問題? error_log似乎告訴了很多。我是網絡開發的新手,我可能會犯一些明顯的錯誤。非常感謝你!
它的工作原理!謝謝! – garthcn 2011-05-13 04:38:39