我正在尝试让 CherryPy 应用程序在 ubuntu 上的 apache2/mod_wsgi 下运行。我正在按照此处概述的教程进行操作,并且我的配置几乎相同。访问站点的根目录时,我收到 500 Internal Server Error。日志中唯一的错误是:
[Mon Dec 03 04:43:06 2012] [error] [client 64.189.251.239] Premature end of script headers: index.py
我尝试了本教程的几种变体,但没有收到任何重大错误。有任何想法吗?
我的阿帕奇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]