我有一些小型 django 项目与 apache 和 mod_wsgi 在同一台服务器上工作。我用虚拟环境安装了另一个项目,并在 Apache conf 文件中为其设置了设置:
<VirtualHost XXX.XXX.XXX.XXX:81 >
ServerName mywebsite.com
CustomLog /var/www/httpd-logs/mywebsite.com.access.log combined
DocumentRoot /var/www/empirik/data/www/mywebsite.com
ErrorLog /var/www/httpd-logs/mywebsite.com.error.log
ServerAlias www.mywebsite.com
SuexecUserGroup empirik empirik
WSGIScriptAlias / /var/www/empirik/data/www/mywebsite.com/myproject/wsgi.py
WSGIDaemonProcess mywebsite.com python-path=/var/www/empirik/data/www/mywebsite.com/env/lib/python2.7/site-packages
<Directory /var/www/empirik/data/www/mywebsite.com/myproject>
Order deny,allow
Allow from All
</Directory>
<Directory /var/www/empirik/data/www/mywebsite.com/myproject/static>
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
当我尝试加载网站服务器时,大约 50% 的时间返回 500 错误或另一个网站的内容,并且 apache 日志文件中有一些我无法理解的奇怪错误,因为它试图加载另一个网站的项目设置:
[Wed May 22 10:18:47 2013] [error] [client 66.249.78.234] mod_wsgi (pid=32361): Exception occurred processing WSGI script '/var/www/empirik/data/www/mywebsite.com/myproject/wsgi.py'.
[Wed May 22 10:18:47 2013] [error] [client 66.249.78.234] Traceback (most recent call last):
[Wed May 22 10:18:47 2013] [error] [client 66.249.78.234] File "/usr/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 219, in __call__
[Wed May 22 10:18:47 2013] [error] [client 66.249.78.234] self.load_middleware()
[Wed May 22 10:18:47 2013] [error] [client 66.249.78.234] File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 39, in load_middleware
[Wed May 22 10:18:47 2013] [error] [client 66.249.78.234] for middleware_path in settings.MIDDLEWARE_CLASSES:
[Wed May 22 10:18:47 2013] [error] [client 66.249.78.234] File "/usr/local/lib/python2.7/site-packages/django/utils/functional.py", line 184, in inner
[Wed May 22 10:18:47 2013] [error] [client 66.249.78.234] self._setup()
[Wed May 22 10:18:47 2013] [error] [client 66.249.78.234] File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
[Wed May 22 10:18:47 2013] [error] [client 66.249.78.234] self._wrapped = Settings(settings_module)
[Wed May 22 10:18:47 2013] [error] [client 66.249.78.234] File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 95, in __init__
[Wed May 22 10:18:47 2013] [error] [client 66.249.78.234] raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
[Wed May 22 10:18:47 2013] [error] [client 66.249.78.234] ImportError: Could not import settings 'anotherproject.settings' (Is it on sys.path?): No module named anotherproject.settings
另一个问题是为什么它仍然使用默认系统 python 而不是来自 virtualenv?请帮忙!