在Mac OS X上配置mod_wsgi?

时间:2011-05-13 03:21:19

标签: django apache macos mod-wsgi wsgi

我一直在尝试将mod_wsgi配置两天,但仍然没有运气。这是我做的:

  • 创建示例django项目mysite。运行python manage.py runserver并确保其正常运行
  • apache下创建mysite目录,创建apache_django_wsgi.confmysite.wsgi和空__init__.py

apache_django_wsgi.conf的内容:

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> 

mysite.wsgi的内容

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 个答案:

答案 0 :(得分:1)

不要将WSGIPythonHome设置为启动它不需要。它应该只在某些情况下才需要,而这不是其中之一。

在这种情况下,您已将其设置为错误的值。通过权利这个错误的事实不应该导致问题,因为Python应该回归到使用正确的默认值,但它可能由于某种原因不能这样做。

您也可以删除该行:

WSGIRestrictStdout Off

因为mod_wsgi 3.3不需要。