我在使用mod_wsgi在Apache中部署我的buildout项目(Django)时遇到了一些问题。
我的文件夹结构:
t/
bootstrap.py
setup.py
bin/
buildout
django
django.wsgi
.....
eggs/
raven-3.1.13-py2.7.egg
..........
parts
project
develop-eggs
src/
some files
myapp/
files
settings.py
apicontainer/
....
Appache配置文件:
<VirtualHost *:80>
DocumentRoot /home/.../tests/website
ServerName testapp.com
<Directory /home/.../tests/website>
Order allow,deny
Allow from all
</Directory>
Alias /website/ /home/.../tests/website/
WSGIDaemonProcess testapp.com processes=2 threads=15 display-name=%{GROUP}
WSGIProcessGroup testapp.com
# ........ pointing to buildout's django.wsgi ..........
WSGIScriptAlias / /home/.../tests/t/bin/django.wsgi
WSGIPassAuthorization On
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
./仓/ django.wsgi
#!/usr/bin/python
import sys
sys.path[0:0] = [
'/home/.../tests/t/eggs/raven-3.1.13-py2.7.egg',
'/usr/lib/python2.7/dist-packages',
...........
...........
'/home/.../tests/t/eggs/djangorecipe-1.5-py2.7.egg',
'/home/.../tests/t/eggs/zc.recipe.egg-2.0.0a3-py2.7.egg',
'/home/.../tests/t',
]
import djangorecipe.wsgi
application = djangorecipe.wsgi.main('testproj.settings', logfile='')
buildout.cfg
[buildout]
parts = python
django
develop = .
eggs = raven
.....
.....
[python]
recipe = zc.recipe.egg
interpreter = python
eggs = ${buildout:eggs}
[django]
recipe = djangorecipe
wsgi = true
project = testproj
settings = settings
eggs = ${buildout:eggs}
我得到的apache错误日志是:
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1] mod_wsgi (pid=9772): Exception occurred processing WSGI script '/home/.../tests/t/bin/django.wsgi'.
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1] Traceback (most recent call last):
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 272, in __call__
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1] response = self.get_response(request)
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py", line 153, in get_response
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1] response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py", line 218, in handle_uncaught_exception
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1] return callback(request, **param_dict)
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/dist-packages/django/utils/decorators.py", line 93, in _wrapped_view
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1] response = view_func(request, *args, **kwargs)
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/dist-packages/django/views/defaults.py", line 30, in server_error
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1] t = loader.get_template(template_name) # You need to create a 500.html template.
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/dist-packages/django/template/loader.py", line 157, in get_template
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1] template, origin = find_template(template_name)
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/dist-packages/django/template/loader.py", line 138, in find_template
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1] raise TemplateDoesNotExist(name)
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1] TemplateDoesNotExist: 500.html
我将prmission(777)给bin文件夹。
为了测试wsgi的工作,我改变了我的django.wsgi,如下所示,我将它还原为旧的。
def application(environ, start_response):
status = '200 OK'
output = 'Hello World!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
它给了我结果Hello World!
你能帮我找出问题吗?