首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在CherryPy下运行mod_wsgi

在CherryPy下运行mod_wsgi
EN

Stack Overflow用户
提问于 2012-12-03 05:02:58
回答 1查看 2.5K关注 0票数 1

我正试图在ubuntu上的apache2/mod_wsgi下运行一个CherryPy应用程序。我正在遵循概述这里的教程,我的配置几乎是相同的。访问站点根目录时,我会收到一个500内部服务器错误。日志中唯一的错误是:

代码语言:javascript
复制
[Mon Dec 03 04:43:06 2012] [error] [client 64.189.251.239] Premature end of script headers: index.py

我尝试了几个版本的教程,但我没有收到任何重大错误。有什么想法吗?

我的Apache VirtualHost

代码语言:javascript
复制
...
    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脚本:

代码语言:javascript
复制
#!/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应用程序会产生完全相同的错误:

代码语言:javascript
复制
#!/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]
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-12-03 05:15:38

我建议您用一个超级简单的wsgi应用程序替换cherrypy index.py脚本来测试您的apache配置。

代码语言:javascript
复制
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脚本之前,请确保该脚本有效。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13677431

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档