0

我能够为 Python 2.5.4 编译 mod_wsgi。它现在被加载到 apache 模块中。我通过命令确认了

httpd.exe -M
.
.
wsgi_module(shared)
php5_module(shared)

但我无法运行测试文件(hello.wsgi),它位于文件夹 c:/apache/htdocs/wsgi 中:因此文件路径变为 c:/apache/htdocs/wsgi/hello.wsgi

我的 hello.wsgi 文件包含:

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]

我在 httpd.conf 中添加了以下几行:

LoadModule wsgi_module modules/mod_wsgi.so

<IfModule wsgi_module>
    WSGIScriptAlias /wsgi/ "c:/apache/htdocs/wsgi/hello.wsgi"

    <Directory "c:/apache/htdocs/wsgi">
            Order deny,allow
            allow from All
    </Directory>
</IfModule>

我的 Apache 错误日志是:

[Sat Nov 19 15:29:32 2011] [warn] pid file C:/apache/logs/httpd.pid overwritten -- Unclean shutdown of previous Apache run?
[Sat Nov 19 15:29:32 2011] [warn] mod_wsgi: Compiled for Python/2.5.
[Sat Nov 19 15:29:32 2011] [warn] mod_wsgi: Runtime using Python/2.5.4.
[Sat Nov 19 15:29:33 2011] [notice] Apache/2.2.21 (Win32) mod_wsgi/3.3 Python/2.5.4 PHP/5.3.8 configured -- resuming normal operations
[Sat Nov 19 15:29:33 2011] [notice] Server built: Sep  9 2011 10:26:10
[Sat Nov 19 15:29:33 2011] [notice] Parent: Created child process 2296
[Sat Nov 19 15:29:33 2011] [warn] mod_wsgi: Compiled for Python/2.5.
[Sat Nov 19 15:29:33 2011] [warn] mod_wsgi: Runtime using Python/2.5.4.
[Sat Nov 19 15:29:33 2011] [notice] Child 2296: Child process is running
[Sat Nov 19 15:29:33 2011] [notice] Child 2296: Acquired the start mutex.
[Sat Nov 19 15:29:33 2011] [notice] Child 2296: Starting 64 worker threads.
[Sat Nov 19 15:29:33 2011] [notice] Child 2296: Starting thread to listen on port 80.
[Sat Nov 19 15:30:21 2011] [error] [client 127.0.0.1] File does not exist: C:/apache/htdocs/wsgi

更新

我从别名中删除了尾部斜杠,我已将我的 wsgi 文件夹从 htdocs 移动到 apache 并创建了一个 vhost 文件:

<VirtualHost 127.0.0.1:80>
    <Directory "C:/apache/wsgi">
        Options FollowSymLinks Indexes
        AllowOverride All
        Order deny,allow
        allow from All
    </Directory>
    ServerName 127.0.0.1
    ServerAlias 127.0.0.1
    WSGIScriptAlias /wsgi "C:/apache/wsgi/hello.wsgi"
    DocumentRoot "C:/apache/wsgi"
    ErrorLog "C:/apache/logs/127.0.0.1.err"
    CustomLog "C:/apache/logs/127.0.0.1.log" combined
</VirtualHost>

但是现在我的 Apache 给出了一些 Windows 错误,例如:

Faulting application name: httpd.exe, version: 2.2.21.0, time stamp: 0x4e6a3015
Faulting module name: ntdll.dll, version: 6.1.7601.17514, time stamp: 0x4ce7ba58
Exception code: 0xc0000005
Fault offset: 0x00038da9
Faulting process id: 0xc4c
Faulting application start time: 0x01cca6c0f9ccd446
Faulting application path: C:\apache\bin\httpd.exe
Faulting module path: C:\Windows\SysWOW64\ntdll.dll
Report Id: 3ba0b9e0-12b4-11e1-b285-005056c00008

需要一些帮助。

谢谢。

4

1 回答 1

1

这听起来像是我在系统上未安装 Visual C++ 2008 Redistributable (msvcr90.dll) 时遇到的错误。但首先,请检查(使用 Dependency Walker)httpd.exe并且mod_wsgi.so使用完全相同msvcr90.dll

  • 一样的名字
  • 同一目录
  • 同版本
  • 相同的时间戳

如果它们使用不同的 DLL 名称(例如msvcr90.dllmsvcr100.dll),那么您必须使用相同的编译器(例如 Visual Studio 2008)重新编译它们。

如果他们使用相同的 DLL 名称,但版本不同或在不同的目录中,那么您可能会遇到与 BitNami DjangoStack 相同的问题。

因为msvcr90.dll没有在系统范围内安装C:\Windows\WinSxShttpd所以只能运行,因为在与 httpd.exe 相同的目录中存在并行程序集的“xcopy 部署”:

  • Microsoft.VC90.CRT.manifest
  • msvcr90.dll

如果这些文件不存在,它将由于缺少对 的依赖而失败msvcr90.dll,或者出现以下错误:

此应用程序无法启动,因为应用程序配置不正确。重新安装应用程序可能会解决此问题。

(即找到了 DLL,但没有使其有效的清单)。

尽管httpd.exe以这种方式运行,但它无法可靠地加载也使用的 DLL msvcr90.dll

  • 如果 DLL 在其 OWN 目录中有“xcopy 部署”,那么它会将DLL 的另一个副本加载到进程中(因为它是 DLL 的不同副本?)。这会导致进程内存空间中的第二个堆,如果内存在 DLL 和 httpd 之间传递(由一个分配并由另一个释放),则可能会使进程崩溃。我想这就是你所看到的。
  • 如果 DLL在其自己的目录中没有“xcopy 部署”,那么它将无法加载,并在系统事件日志中显示 SideBySide 或 Windows 错误报告错误。

您可以在Python bug 4120上看到更多关于此类问题的信息,尽管这不是对问题的清晰、完整和明确的解释,而且我还没有找到。

我发现运行此堆栈的唯一可靠方法是在系统范围内安装Visual C++ 2008 可再发行组件,它将副本与清单一起放置msvcr90.dll在子目录中C:\Windows\WinSxS以使其工作。

这应该(我认为)导致 Windows 完全忽略应用程序和 DLL 目录中的Microsoft.VC90.CRT.manifestmsvcr90.dll文件。两者都应该在 中使用相同的 DLL C:\Windows\WinSxS,并且它应该只加载到进程中一次。

于 2012-07-12T10:37:38.880 回答