Debian/Apache2下mod-wsgi段错误

3 投票
1 回答
2548 浏览
提问于 2025-04-16 07:20

我正在尝试在Apache2下运行mod-wsgi,目的是想和Django一起使用。

现在我只是想让一个基本的应用程序运行,但遇到了段错误(segmentation fault)。如果有任何建议可以帮助我找到错误的原因,我会非常感激,因为我现在卡住了。

我是在Debian/Lenny系统上,使用的是Apache、mod-wsgi和Python 2.5的标准版本。我检查过,mod-wsgi是链接到/usr/lib/libpython2.5.so.1.0的。我之前安装过Python 2.4,但为了避免出现版本错误,我把它卸载了。

我的脚本文件是:

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]

我的配置是:

WSGIScriptAlias /myapp /var/www/test/myapp.wsgi

<Directory /var/www/test/myapp.wsgi>
Order allow,deny
Allow from all
</Directory>

当我尝试访问这个网址时,我在Apache的错误日志中看到了这个信息。

[Fri Nov 19 09:29:58 2010] [info] mod_wsgi (pid=7190): Create interpreter 'morpheus.gateway.2wire.net|/myapp'.
[Fri Nov 19 09:29:58 2010] [info] mod_wsgi (pid=7331): Attach interpreter ''.
[Fri Nov 19 09:29:58 2010] [notice] child pid 7190 exit signal Segmentation fault (11)

其他方面Python似乎运行得很好,我在内置服务器上运行我的Django应用没有问题。

顺便说一下,我最开始是想让我的Django应用运行,但遇到了这个错误:

[Fri Nov 19 08:25:08 2010] [info] mod_wsgi (pid=6861): Create interpreter 'morpheus.gateway.2wire.net|/curtana'.
[Fri Nov 19 08:25:08 2010] [error] [client 192.168.2.70] mod_wsgi (pid=6861): Exception occurred processing WSGI script '/var/data/curtana/curtana.wsgi'.
[Fri Nov 19 08:25:08 2010] [error] [client 192.168.2.70]   File "/var/data/curtana/curtana.wsgi", line 1
[Fri Nov 19 08:25:08 2010] [error] [client 192.168.2.70]      import sys
[Fri Nov 19 08:25:08 2010] [error] [client 192.168.2.70]           ^
[Fri Nov 19 08:25:08 2010] [error] [client 192.168.2.70]  SyntaxError: invalid syntax

所以我才尝试了这个基本的应用。

感谢任何建议。

编辑补充,这里有一个回溯信息:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb751a700 (LWP 8092)]
0xb6b3a920 in PyParser_AddToken (ps=0x8543f90, type=8, str=0x845a480 ")", 
    lineno=1, col_offset=39, expected_ret=0xbfffe378) at ../Parser/parser.c:274
274     ../Parser/parser.c: No such file or directory.
        in ../Parser/parser.c
(gdb) backtrace
#0  0xb6b3a920 in PyParser_AddToken (ps=0x8543f90, type=8, str=0x845a480 ")", 
    lineno=1, col_offset=39, expected_ret=0xbfffe378) at ../Parser/parser.c:274
#1  0xb6b3ab86 in parsetok (tok=0x8535460, g=<value optimized out>, start=257, 
    err_ret=0xbfffe360, flags=<value optimized out>)
    at ../Parser/parsetok.c:194
#2  0xb6bec5eb in PyParser_SimpleParseFileFlags (fp=0x84f3288, 
    filename=0x85301b0 "/var/www/test/myapp.wsgi", start=257, flags=0)
    at ../Python/pythonrun.c:1404
#3  0xb6c76877 in ?? () from /usr/lib/apache2/modules/mod_wsgi.so
#4  0x084f3288 in ?? ()
#5  0x085301b0 in ?? ()
#6  0x00000101 in ?? ()
#7  0x00000000 in ?? ()

1 个回答

2

查看mod_wsgi的文档,找找里面关于崩溃的部分。可以从以下链接开始:

http://code.google.com/p/modwsgi/wiki/FrequentlyAskedQuestions http://code.google.com/p/modwsgi/wiki/InstallationIssues

崩溃的原因可能是和mod_python发生了冲突,或者是运行时找到了错误的Python安装。

之后,可以按照以下链接的说明检查安装情况:

http://code.google.com/p/modwsgi/wiki/CheckingYourInstallation


更新 1

在评论中提到的生成堆栈跟踪的过程,可以在以下链接找到详细说明:

http://code.google.com/p/modwsgi/wiki/DebuggingTechniques

撰写回答