【问题标题】:Setting up Python with WSGI on Apache for a directory在 Apache 上使用 WSGI 为目录设置 Python
【发布时间】:2013-01-02 20:15:28
【问题描述】:

我正在尝试使用 WSGI 为 Apache 上的特定目录设置 Python,但出现以下错误:

mod_wsgi (pid=3857): Target WSGI script '/var/www/test/test.py' does not contain WSGI application 'application'.

我的 test.py 包含:

print 'Hello, World!'

我的 wsgi.conf 包含:

LoadModule wsgi_module modules/mod_wsgi.so

WSGIPythonHome /usr/local/bin/python2.7

Alias /test/ /var/www/test/test.py

<Directory /var/www/test>
    SetHandler wsgi-script
    Options ExecCGI
    Order deny,allow
        Allow from all
</Directory>

最重要的是,有趣的是,Web 浏览器返回“404 Not Found”错误,但幸运的是,error_log 更有启发性。

我做错了什么?

【问题讨论】:

    标签: python python-2.7 mod-wsgi wsgi


    【解决方案1】:

    你使用 WSGI 就像它是 CGI 一样(奇怪的是没有标题)。

    您需要做的,因为您的直接问题是从http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide 调整以下内容

    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]
    

    所以你有 application 出席。

    并且来自引用的文档。

    注意 mod_wsgi 要求 WSGI 应用程序入口点是 称为“应用程序”。如果你想把它叫做别的东西,那么你 需要显式配置 mod_wsgi 以使用其他名称。 因此,不要随意更改函数的名称。如果你 做,即使您正确设置了其他所有内容,应用程序也会 找不到。

    【讨论】:

    • WSGICallableObject 应用函数名
    • 我知道这已经过时了,但这会返回`TypeError: sequence of byte string values expected, value of type str found`对我来说
    猜你喜欢
    • 2011-10-07
    • 1970-01-01
    • 2010-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多