我正在尝试运行在同一VirtualHost
上配置的两个wsgi应用程序。其中一个应用myapp
是指定的标准hello-world代码here。加载绝对正常。另一个应用程序uiapp
是Django站点。它失败了ImportError
。
我在wsgi docs中读到python-path
的值已附加到sys.path
,因此我在WSGIDaemonProcess
uiapp
中指定了 [ . . . ]
# processGroups
WSGIProcessGroup uiapp
WSGIProcessGroup myapp
# configurations for django sites
WSGIScriptAlias /uiapp "/some/path/ui_dir/site_prod/wsgi.py"
WSGIScriptAlias /myapp "/some/other/path/myapp.wsgi"
# daemons
WSGIDaemonProcess uiapp processes=2 threads=25 display-name=site_prod_wsgi python-path=/some/path/ui_dir
WSGIDaemonProcess myapp processes=2 threads=25 display-name=helloworld_wsgi
# doc root for /uiapp
<Directory "/some/path/ui_dir/site_prod">
Order allow,deny
Allow from all
</Directory>
# doc root for /myapp
<Directory "/some/other/path">
Order allow,deny
Allow from all
</Directory>
[ . . . ]
。 / p>
我无法弄清楚问题是Python代码还是Apache配置。
这是我的虚拟主机配置:
python-path
我已尝试将uiapp
的{{1}}更改为/some/path/ui_dir/site_prod
,但即使这样也会因同样的错误而失败。
错误日志是:
mod_wsgi (pid=32652): Exception occurred processing WSGI script '/some/path/ui_dir/site_prod/wsgi.py'.
Traceback (most recent call last):
File "/home/usr/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 219, in __call__
self.load_middleware()
File "/home/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 39, in load_middleware
for middleware_path in settings.MIDDLEWARE_CLASSES:
File "/home/usr/local/lib/python2.7/site-packages/django/utils/functional.py", line 184, in inner
self._setup()
File "/home/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
self._wrapped = Settings(settings_module)
File "/home/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 95, in __init__
raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'site_prod.settings' (Is it on sys.path?): No module named site_prod.settings
这是/some/path/ui_dir/site_prod/wsgi.py
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "site_prod.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)
请帮我弄清楚我做错了什么。
答案 0 :(得分:4)
你不能在这样的行中有两个WSGIProcessGroup指令。只会使用最后一个。因此,您实际上是将两个应用程序发送到同一个守护程序进程组而不是不同的进程组。完成并在同一个过程中执行它们后,您将遇到以下所述的setdefault()问题:
将WSGIProcessGroup指令移动到与各个WSGI脚本文件位置相关的Directory块中。
答案 1 :(得分:1)
如果您查看以前版本的django docs版本1.3而不是1.4,那么How to use Django with Apache and mod_wsgi部分可以帮助解决您的问题。我在配置虚拟主机时遇到了同样的问题。因此,而不是在虚拟主机配置中指定python-path=/some/path/ui_dir
。您可以在/some/path/ui_dir/site_prod/wsgi.py
中将该行添加到该文件中。在导入和运行django之前,将这些行放在文件顶部的行之前。
<强>码强>
import sys
path = '/some/path/ui_dir'
if path not in sys.path:
sys.path.append(path)
答案 2 :(得分:0)
...并确保在wsgi.py中设置了DJANGO_SETTINGS_MODULE
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings.could.be.somewhere.else'
答案 3 :(得分:0)
试试这个:
虚拟主机:
<Virtualhost project.dev>
DocumentRoot "/full/path/to/project/root/"
WSGIScriptAlias / /full/path/to/wsgi/file/wsgi.py
</Virtualhost>
wsgi.py:
sys.path = ['path/to/project/root'] + sys.path