如何让 apache 使用带有 mod_wsgi 的 python 2?

如何让 apache 使用带有 mod_wsgi 的 python 2?

我有一台 Arch Linux 服务器,以前使用 Python 2.7.3 与 Apache 和 mod_wsgi-3.4-2 运行良好。我在服务器上安装了 Python 2.7.3 和 3.3.0,两个可执行文件都位于/usr/bin。最近它开始使用 Python 3。我需要 Apache 恢复使用 Python 2.7。error_log单个请求如下所示:

[Thu Dec 13 00:18:50 2012] [notice] Apache/2.2.23 (Unix) mod_wsgi/3.4 Python/3.3.0 mod_ssl/2.2.23 OpenSSL/1.0.1c DAV/2 PHP/5.4.9 configured -- resuming normal operations
[Thu Dec 13 00:18:53 2012] [error] 3.3.0 (default, Sep 29 2012, 16:08:02) 
[Thu Dec 13 00:18:53 2012] [error] [GCC 4.7.1 20120721 (prerelease)]
[Thu Dec 13 00:18:53 2012] [error] 
[Thu Dec 13 00:18:53 2012] [error] [client 192.168.0.7] mod_wsgi (pid=6156): Target WSGI script '/path/to/webapp/apache/wsgi.py' cannot be loaded as Python module.
[Thu Dec 13 00:18:53 2012] [error] [client 192.168.0.7] mod_wsgi (pid=6156): Exception occurred processing WSGI script '/path/to/webapp/apache/wsgi.py'.
[Thu Dec 13 00:18:53 2012] [error] [client 192.168.0.7] Traceback (most recent call last):
[Thu Dec 13 00:18:53 2012] [error] [client 192.168.0.7]   File "/path/to/webapp/apache/wsgi.py", line 4, in <module>
[Thu Dec 13 00:18:53 2012] [error] [client 192.168.0.7]     from django.core.handlers import wsgi
[Thu Dec 13 00:18:53 2012] [error] [client 192.168.0.7] ImportError: No module named 'django'

这是我的wsgi.py文件:

import os
import sys
from django.core.handlers import wsgi

site_path = '/path/to/webapp/csis3150site'
if site_path not in sys.path:
  sys.path.append(site_path)

# Set DJANGO_SETTINGS_MODULE env variable
os.environ['DJANGO_SETTINGS_MODULE'] = 'csis3150site.settings'

# start wsgi
application = wsgi.WSGIHandler()

这是来自的与 mod_wsgi 相关的配置httpd.conf

LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias / /path/to/webapp/apache/wsgi.py 
WSGIPythonPath /path/to/webapp

答案1

我能够通过卸载该mod_wsgi包并用该包替换它来解决这个问题mod_wsgi2

相关内容