【问题标题】:Configure mod_wsgi on Mac OS X?在 Mac OS X 上配置 mod_wsgi?
【发布时间】:2011-08-24 14:56:27
【问题描述】:

我已经尝试配置 mod_wsgi 两天了,但仍然没有运气。这是我所做的:

  • 创建一个示例 django 项目mysite。运行 python manage.py runserver 并确保它正常工作
  • 在mysite下创建apache目录,创建apache_django_wsgi.conf、mysite.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/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 似乎说明了很多。我是 Web 开发的新手,我可能犯了一些明显的错误。非常感谢!

【问题讨论】:

    标签: django apache macos mod-wsgi wsgi


    【解决方案1】:

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

    在这种情况下,您将其设置为错误的值。按理说,它错误的事实不应该引起问题,因为 Python 应该回退到使用正确的默认值,但由于某种原因它可能不会这样做。

    你也可以删除该行:

    WSGIRestrictStdout Off
    

    因为 mod_wsgi 3.3 不需要。

    【讨论】:

      猜你喜欢
      • 2010-12-12
      • 1970-01-01
      • 1970-01-01
      • 2010-09-23
      • 2013-02-21
      • 2012-04-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-27
      相关资源
      最近更新 更多