尝试在Ubuntu Lucid Lynx上启动Apache2 mod_wsgi而无法成功运行Django

我有一个最小安装ubuntu lucid-lynx与约256MB内存的小vps ,它是新安装的没有什么特别的运行。 我试图部署django到它,而我成功地运行服务器使用manage.py,我不能得到Apache与wsgi工作:

# service apache2 start && service apache2 status * Starting web server apache2 [ OK ] Apache is NOT running. 

Erorr日志/var/log/apache2/error.log

 [Thu Apr 14 21:17:29 2011] [warn] pid file /var/run/apache2.pid overwritten -- Unclean shutdown of previous Apache run? [Thu Apr 14 21:17:29 2011] [notice] Apache/2.2.14 (Ubuntu) mod_wsgi/2.8 Python/2.6.5 configured -- resuming normal operations [Thu Apr 14 21:17:29 2011] [alert] (11)Resource temporarily unavailable: apr_thread_create: unable to create worker thread [Thu Apr 14 21:17:29 2011] [error] Exception KeyError: KeyError(-1216795792,) in <module 'threading' from '/usr/lib/python2.6/threading.pyc'> ignored [Thu Apr 14 21:17:29 2011] [alert] (11)Resource temporarily unavailable: apr_thread_create: unable to create worker thread [Thu Apr 14 21:17:29 2011] [error] Exception KeyError: KeyError(-1216795792,) in <module 'threading' from '/usr/lib/python2.6/threading.pyc'> ignored [Thu Apr 14 21:17:31 2011] [alert] No active workers found... Apache is exiting! 

我的apacheconfiguration文件/etc/apache2/httpd.conf

 WSGIScriptAlias / /usr/local/django/deals/apache/django.wsgi <Directory /usr/local/django/deals/apache> Order deny,allow Allow from all </Directory> 

/usr/local/django/deals/apache/django.wsgi文件:

 import os import sys path = '/usr/local/django/deals' if path not in sys.path: sys.path.append(path) os.environ['DJANGO_SETTINGS_MODULE'] = 'deals.settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler() 

似乎要安装:

 # dpkg -l \*apache\* |grep -E '^ii' ii apache2 2.2.14-5ubuntu8.4 Apache HTTP Server metapackage ii apache2-mpm-worker 2.2.14-5ubuntu8.4 Apache HTTP Server - high speed threaded mod ii apache2-utils 2.2.14-5ubuntu8.4 utility programs for webservers ii apache2.2-bin 2.2.14-5ubuntu8.4 Apache HTTP Server common binary files ii apache2.2-common 2.2.14-5ubuntu8.4 Apache HTTP Server common files ii libapache2-mod-wsgi 2.8-2ubuntu1 Python WSGI adapter module for Apache 

我终于想出了如何解决这个问题。 首先,我从10.04升级到10.10 ,因为服务器只提供了128MB(256MB突发),并在中期升级。 也许这个问题的解决办法是简单地升级Ubuntu的 。 不过,我通过从源代码安装来升级mod-wsgi ,但这似乎并没有影响到任何东西。

当我通过apt-get install apache2-mpm-prefork所以它会使用那个来代替apache-mpm-worker 。 我不确定是否问题是有apache-mpm-worker导致我的其他错误不被logging,也许下一个遇到问题的人可以尝试跳过这一步。 当我切换到apache-mpm-worker时 , apache错误日志给出了以下错误。

  mod_wsgi (pid=1436): Exception occurred processing WSGI script '/usr/local/django/deals/apache/django.wsgi'. Traceback (most recent call last): File "/usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/core/handlers/wsgi.py", line 250, in __call__ self.load_middleware() File "/usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/core/handlers/base.py", line 39, in load_middleware for middleware_path in settings.MIDDLEWARE_CLASSES: File "/usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/utils/functional.py", line 276, in __getattr__ self._setup() File "/usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/conf/__init__.py", line 42, in _setup self._wrapped = Settings(settings_module) File "/usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/conf/__init__.py", line 89, in __init__ raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e)) ImportError: Could not import settings 'deals.settings' (Is it on sys.path?): No module named deals.setting 

这是因为我们无法导入设置模块。 与Django文档的wsgi集成解释说,我需要添加包含path,一旦我更新/usr/local/django/deals/apache/django.wsgi一切顺利。

 import os, sys sys.path.append('/usr/local/django/deals') sys.path.append('/usr/local/django') os.environ['DJANGO_SETTINGS_MODULE'] = 'deals.settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler() 

这是一个旧的mod_wsgi错误。 将mod_wsgi更新到更新的版本。