python - 在 Apache 上使用 WSGI 为目录设置 Python

标签 python python-2.7 mod-wsgi wsgi

我正在尝试为 Apache 上的特定目录设置带有 WSGI 的 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 更有启发性。

我做错了什么?

最佳答案

您正在使用 WSGI,就好像它是 CGI(奇怪的是没有 header )。

您需要做的是,针对您当前的问题,改编自 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

来自引用的文档。

Note that mod_wsgi requires that the WSGI application entry point be called 'application'. If you want to call it something else then you would need to configure mod_wsgi explicitly to use the other name. Thus, don't go arbitrarily changing the name of the function. If you do, even if you set up everything else correctly the application will not be found.

关于python - 在 Apache 上使用 WSGI 为目录设置 Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14410455/

相关文章:

python - 更Pythonic的方式来嵌套函数

python - 'NameError : global name is not defined' under pdb, 对于确实存在的字典

python - Scrapy startproject 给出奇怪的错误

Apache2 和 mod_wsgi : Truncated or oversized response headers received from daemon process

python - Python 中的 Unicode 和 `decode()`

javascript - 如何使用递归遍历嵌套数组?

python - 尝试使用 capstone 通过 winappdbg 进行反汇编时出错

python - 将 namedtuple 转换为 python 列表并生成 CSV

python - 在 apache 中使用子进程时出现“命令未找到”错误

django - 使用 mod_wsgi 在 Apache2 上部署 Django - Django 项目的正确位置?