开发者

Configure mod_wsgi on Mac OS X?

开发者 https://www.devze.com 2023-03-05 08:18 出处:网络
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

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 occ开发者_运维百科urred 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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消