我想在ubuntu上的apache2 / mod_wsgi下运行一个CherryPy应用程序。我按照here概述的教程,我的配置几乎相同。访问站点的根目录时,收到500内部服务器错误。日志中唯一的错误是:
[Mon Dec 03 04:43:06 2012] [error] [client 64.189.251.239] Premature end of script headers: index.py
我已经尝试了几个教程的变体,但我没有收到任何重大错误。有什么想法吗?
我的Apache VirtualHost
:
...
WSGIScriptAlias / /var/www/example.com/uba/index.py
DocumentRoot /var/www/example.com/uba/
<Directory />
Options +ExecCGI Indexes FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/example.com/uba/>
Options +ExecCGI -Indexes -FollowSymLinks -MultiViews
WSGIApplicationGroup %{GLOBAL}
AllowOverride All
Order allow,deny
allow from all
</Directory>
...
我的index.py脚本:
#!/usr/bin/python
import sys
sys.stdout = sys.stderr
import atexit
import threading
import cherrypy
cherrypy.config.update({'environment': 'embedded'})
if cherrypy.__version__.startswith('3.0') and cherrypy.engine.state == 0:
cherrypy.engine.start(blocking=False)
atexit.register(cherrypy.engine.stop)
class Root(object):
def index(self):
return 'Hello World!'
index.exposed = True
application = cherrypy.Application(Root(), script_name=None, config=None)
更新#1:
运行这个非常基本的wsgi应用程序会产生完全相同的错误:
#!/usr/bin/python
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]
答案 0 :(得分:1)
我建议您使用超级简单的wsgi应用程序替换cherrypy index.py脚本来测试您的apache配置。
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]
确保在尝试使用cherrypy脚本之前有效。