坚持使用apache + mod_wsgi部署django

时间:2012-06-14 13:50:05

标签: django deployment apache2 mod-wsgi error-log

我收到500内部服务器错误,并在日志文件中写道:

[Thu Jun 14 16:30:22 2012] [error] [client 127.0.0.1] ImportError: Could not import settings 'mysite.settings' (Is it on sys.path?): No module named mysite.settings

这是我的httpd.conf:

ServerName localhost

<VirtualHost *:80>
    ServerAdmin ttt@mysite.com
    ServerName mysite.com
    ServerAlias www.mysite.com
    DocumentRoot /var/www/mysite/
    LogLevel warn
    WSGIDaemonProcess processes=2 maximum-requests=500 threads=1
    WSGIScriptAlias / /var/www/mysite/mysite/wsgi.py
    Alias /media /var/www/mysite/mysite/static/media/
</VirtualHost>

wsgi.py:

import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

1 个答案:

答案 0 :(得分:10)

mod-wsgi文档http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango和Django部署文档https://docs.djangoproject.com/en/1.4/howto/deployment/wsgi/modwsgi/都涉及到这个问题,它注意到项目必须在Python路径上。您可以使用WSGIPythonPath指令或在Django文档中的python-path指令中设置WSGIDaemonProcess。或者您可以将其作为mod-wsgi docs状态添加到wsgi文件中的sys.path