在 Windows 上使用 Apache2.2 配置 mod_wsgi 3.3

发布于 2024-12-17 03:19:48 字数 3190 浏览 6 评论 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 的文件夹创建了一个虚拟主机文件:

<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

需要一些帮助。

谢谢。

I was able to compile mod_wsgi for Python 2.5.4. It is now loaded into apache modules. I confirmed it by command

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

But I am unable to run a test file(hello.wsgi), it is located in folder c:/apache/htdocs/wsgi : so the path of file becomes c:/apache/htdocs/wsgi/hello.wsgi

My hello.wsgi file contains:

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]

I added the following lines to 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>

And my Apache Error Log is :

[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

Update

I removed the trailing slash from alias, i have moved my wsgi folder from htdocs to apache & created a vhost file:

<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>

But now my Apache is giving some windows error like:

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

Need Some Help.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘虞初梦 2024-12-24 03:19:48

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

  • 相同的名称
  • 相同的目录相同的
  • 版本
  • 相同的时间戳

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

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

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

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

如果这些文件有没有去过目前,它会由于缺少对 msvcr90.dll 的依赖而失败,或者出现以下错误:

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

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

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

  • 如果该DLL在其自己的网络中具有“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.manifest 和 msvcr90.dll 文件。两者都应该在 C:\Windows\WinSxS 中使用相同的 DLL,并且只能将其加载到进程中一次。

This sounds like the error that I had when the Visual C++ 2008 Redistributable (msvcr90.dll) was not installed on the system. But first, please check (with Dependency Walker) that httpd.exe and mod_wsgi.so are using exactly the same msvcr90.dll:

  • same name
  • same directory
  • same version
  • same timestamp

If they are using different DLL names (e.g. msvcr90.dll and msvcr100.dll) then you must recompile both with the same compiler (e.g. Visual Studio 2008).

If they are using the same DLL name, but different versions or in different directories, then you might be having the same problem that I had, with BitNami DjangoStack.

Because msvcr90.dll was not installed system-wide in C:\Windows\WinSxS, httpd was only able to run at all because there was an "xcopy deployment" of the side-by-side assembly in the same directory as httpd.exe:

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

If these files had not been present, it would have failed due to a missing dependency on msvcr90.dll, or else with this error:

This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem.

(i.e. the DLL was found but without a manifest to make it valid).

Although httpd.exe runs this way, it is not able to reliably load a DLL that also uses msvcr90.dll:

  • If the DLL has an "xcopy deployment" in its OWN directory, then it will load another copy of the DLL into the process (because it's a different copy of the DLL?). This results in a second heap in the process memory space, which can crash the process if memory is passed between the DLL and httpd (allocated by one and freed by the other). I think this is what you're seeing.
  • If the DLL does not have an "xcopy deployment" in its own directory, then it will fail to load with a SideBySide or Windows Error Reporting error in the System event log.

You can see more about this kind of problem on Python bug 4120, although this is not a clear, complete and definitive explanation of the problem, and I have not been able to find one yet.

The only reliable way I found to run this stack was to install the Visual C++ 2008 redistributable system-wide, which places a copy of msvcr90.dll in a subdirectory of C:\Windows\WinSxS along with a manifest to make it work.

This should (I think) cause Windows to completely ignore the Microsoft.VC90.CRT.manifest and msvcr90.dll files in the application and DLL directories. Both should use the same DLL in C:\Windows\WinSxS, and it should only be loaded into the process once.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文