运行 Apache 2.2 的 x64 Windows 7 上的 mod_wsgi 问题

运行 Apache 2.2 的 x64 Windows 7 上的 mod_wsgi 问题

64 位 Win7 Apache 2.2.19,mod_wsgi/3.4-BRANCH Python/2.7.3

日志中未显示任何错误:

[Wed Aug 01 17:44:48 2012] [notice] Apache/2.2.19 (Win64) mod_wsgi/3.4-BRANCH Python/2.7.3 configured -- resuming normal operations
[Wed Aug 01 17:44:48 2012] [notice] Server built: May 28 2011 15:18:56
[Wed Aug 01 17:44:48 2012] [notice] Parent: Created child process 8528
[Wed Aug 01 17:44:48 2012] [debug] mpm_winnt.c(477): Parent: Sent the scoreboard to the child
[Wed Aug 01 17:44:48 2012] [notice] Child 8528: Child process is running
[Wed Aug 01 17:44:48 2012] [debug] mpm_winnt.c(398): Child 8528: Retrieved our scoreboard from the parent.
[Wed Aug 01 17:44:48 2012] [info] Parent: Duplicating socket 556 and sending it to child process 8528
[Wed Aug 01 17:44:48 2012] [debug] mpm_winnt.c(595): Parent: Sent 1 listeners to child 8528
[Wed Aug 01 17:44:48 2012] [debug] mpm_winnt.c(554): Child 8528: retrieved 1 listeners from parent
[Wed Aug 01 17:44:48 2012] [info] mod_wsgi (pid=8528): Initializing Python.
[Wed Aug 01 17:44:48 2012] [info] mod_wsgi (pid=8528): Attach interpreter ''.
[Wed Aug 01 17:44:48 2012] [notice] Child 8528: Acquired the start mutex.
[Wed Aug 01 17:44:48 2012] [notice] Child 8528: Starting 64 worker threads.
[Wed Aug 01 17:44:48 2012] [notice] Child 8528: Starting thread to listen on port 80.

直接按照指南进行配置:

WSGIScriptAlias /wsgi "C:/Program Files/Apache Software Foundation/Apache2.2/wsgi/wsgi_test.py"

<Directory "C:/Program Files/Apache Software Foundation/Apache2.2/wsgi/">
    Order allow,deny
    Allow from all
</Directory>

WSGI应用程序:

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World from wsgi!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]

获取 403 并记录消息:

Options ExecCGI is off in this directory: C:/Program Files/Apache Software Foundation/Apache2.2/wsgi/wsgi_test.py

将选项 +ExecCGI 添加到目录(并将“#!c:\Python27\python.exe”粘贴到应用程序文件的顶部)获取 500 并记录消息:

Premature end of script headers: wsgi_test.py

通过 ExecCGI 直接使用 python 作为脚本语言可以很好地工作,在脚本顶部使用 #!... 并且为另一个目录使用 ExecCGI 配置,等等。

这意味着 WSGIScriptAlias 的行为很像 Alias,并且没有设置 ExecCGI 或正确调用来调用 application() 函数。

我该如何调试?或者是否明显缺少了某些内容?

答案1

您的配置甚至没有被使用,就像从 Apache 配置中的其他地方获取 CGI 配置一样。

将文件重命名为 wsgi_test.wsgi,并相应地更改 WSGIScriptAlias 指令,问题所在可能会变得更加明显。从技术上讲,.py 的 CGI 定义不应覆盖 WSGIScriptAlias。

相关内容