尝试在 Ubuntu Lucid Lynx 上启动 Apache2 mod_wsgi 来运行 Django,但没有成功

尝试在 Ubuntu Lucid Lynx 上启动 Apache2 mod_wsgi 来运行 Django,但没有成功

我有一个小最低安装 内存约为 256mb,是新安装的,没有运行任何特殊程序。我正在尝试部署虽然我使用 manage.py 成功运行了服务器,但我无法在职的:

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

错误日志/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!

我的配置文件/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

答案1

我终于想出了如何解决这个问题。首先,我在升级时遇到麻烦因为服务器只提供 128mb(256mb 突发容量),升级过程中用完了。也许这个问题的解决方案就是直接升级。不过我确实升级了通过从源代码安装描述在这里,但这似乎并没有影响任何事情。

当我安装通过apt-get install apache2-mpm-prefork,所以它会使用它而不是作为调光器建议。我不确定问题是否在于导致我的其他错误未被记录,也许下一个遇到问题的人可以尝试跳过此步骤。当我切换到错误日志却给出了以下错误。

 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

这是因为我们无法导入设置模块。wsgi 与 Django 文档集成解释说我需要添加包含路径,一旦我更新,/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()

答案2

这是旧的 mod_wsgi 错误。请将 mod_wsgi 更新为较新版本。

相关内容