在 Mac OS X 上配置 mod_wsgi?

发布于 2024-11-06 12:33:43 字数 3066 浏览 0 评论 0原文

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

  • 创建一个示例 django 项目 mysite。运行python manage.py runserver并确保它正常工作
  • mysite下创建apache目录,创建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
    包含 /Users/Garth/Dev/web-app/mysite/apache/apache_django_wsgi.conf
  • 运行 sudo apachectl -k start

如果我转到本地主机,我可以看到这些文件和目录列表。但是,如果我转到 localhost/mysite(这是我配置的 WSGIScriptAlias),我会收到内部服务器错误

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 似乎说明了很多信息。我是网络开发新手,我可能犯了一些明显的错误。非常感谢!

I have been trying to configure mod_wsgi for two days and still no luck. Here is what I did:

  • Create a sample django project mysite. Run python manage.py runserver and make sure it's working
  • Create apache directory under mysite, create apache_django_wsgi.conf, mysite.wsgi and an empty __init__.py

Content of 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> 

Content of 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()
  • Download mod_wsgi.so (precompiled binary for Mac OS X) and put it in /usr/libexec/apache2
  • Edit /etc/apache2/httpd.conf,
    add:
    LoadModule wsgi_module libexec/apache2/mod_wsgi.so
    Include /Users/Garth/Dev/web-app/mysite/apache/apache_django_wsgi.conf
  • Run sudo apachectl -k start

If I go to localhost, I can see the files and directories list. But if I go to localhost/mysite (which is the WSGIScriptAlias I configured), I got Internal Server Error.

The error_log of apache is:

[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

Does anyone see where goes wrong? The error_log seems to tell a lot. I'm new to web development, and I might have made some obvious mistakes. Thank you very much!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七禾 2024-11-13 12:33:43

不要因为不需要而开始设置 WSGIPythonHome。仅在某些情况下才需要它,但这不是其中之一。

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

您还可以删除该行:

WSGIRestrictStdout Off

因为 mod_wsgi 3.3 不需要该行。

Don't set WSGIPythonHome for a start it isn't needed. It should only be needed in certain situations and this isn't one of them.

In this case you have set it to a wrong value. By rights the fact it is wrong shouldn't have caused a problem as Python should have fallen back to using correct default value, but it may not do that for some reason.

You can also delete the line:

WSGIRestrictStdout Off

as that isn't needed for mod_wsgi 3.3.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文