2011-05-13 186 views
1

我一直在嘗試配置mod_wsgi兩天,但仍然沒有運氣。這是我做的:在Mac OS X上配置mod_wsgi?

  • 創建一個示例django項目mysite。運行python manage.py runserver並確保它的工作
  • mysite下創建apache目錄,創建apache_django_wsgi.confmysite.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似乎告訴了很多。我是網絡開發的新手,我可能會犯一些明顯的錯誤。非常感謝你!

回答

1

不要將WSGIPythonHome設置爲不需要啓動。它應該只在某些情況下需要,這不是其中之一。

在這種情況下,您已將其設置爲錯誤的值。根據權利,它錯誤的事實不應該引起問題,因爲Python應該已經退回到使用正確的默認值,但是由於某種原因它可能不會這樣做。

您也可以刪除該行:

WSGIRestrictStdout Off 

爲是不需要的mod_wsgi 3.3。

+0

它的工作原理!謝謝! – garthcn 2011-05-13 04:38:39