【问题标题】:Exec format error: apache + mod_wsgi on Mac OS X Lion执行格式错误:Mac OS X Lion 上的 apache + mod_wsgi
【发布时间】:2012-03-02 14:17:58
【问题描述】:

我正在尝试在运行 Lion (Mac OS X 10.7.3) 的 iMac 上使用 Python 2.7、apache、mod_wsgi 和 web2py 设置 Web 开发环境。

我下载并安装了 mod_wsgi v. 3.3 (./configure; make; sudo make install)

它安装在 /usr/libexec/apache2 中。一切看起来都很合理:

07:49 PM ~ [541] otool -L /usr/libexec/apache2/mod_wsgi.so 
/usr/libexec/apache2/mod_wsgi.so:
    /Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
    /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 635.19.0)

07:55 PM ~ [542] file /usr/libexec/apache2/mod_wsgi.so 
/usr/libexec/apache2/mod_wsgi.so: Mach-O universal binary with 2 architectures
/usr/libexec/apache2/mod_wsgi.so (for architecture x86_64): Mach-O 64-bit bundle x86_64
/usr/libexec/apache2/mod_wsgi.so (for architecture i386):   Mach-O bundle i386

在所有 LoadModule 指令之后,我在 /private/etc/apache2/httpd.conf 中添加了几个配置指令。

LoadModule wsgi_module libexec/apache2/mod_wsgi.so
WSGIScriptAlias / /Library/WebServer/Documents

我重新启动了 apache 守护进程。 apache 日志看起来不错:

[Thu Feb 09 19:19:15 2012] [notice] Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8r DAV/2 mod_wsgi/3.3 Python/2.7.2 已配置 -- 恢复正常操作

我将此文件放入 /Library/WebServer/Documents 文件夹:

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]

我通过浏览器执行了它:http://192.168.1.2/test.py

我收到了“500 内部服务器错误”的响应。

我的服务器日志说:

[Thu Feb 09 20:12:10 2012] [error] [client 192.168.1.2] (8)Exec format error: exec of '/Library/WebServer/Documents/test.py' failed
[Thu Feb 09 20:12:10 2012] [error] [client 192.168.1.2] Premature end of script headers: test.py
[Thu Feb 09 20:12:10 2012] [error][client 192.168.1.2] mod_wsgi (pid=4251): Target WSGI script '/Library/WebServer/Documents/favicon.ico' does not contain WSGI application 'application'.

经过大量搜索,我无法找出原因。我什至在文档文件夹中添加了一个 favicon.ico。这导致它被记录:

[Thu Feb 09 19:15:44 2012] [error] [client 192.168.1.2] (8)Exec format error: exec of '/Library/WebServer/Documents/test.py' failed
[Thu Feb 09 19:15:44 2012] [error] [client 192.168.1.2] Premature end of script headers: test.py
[Thu Feb 09 19:15:46 2012] [error] [client 192.168.1.2] mod_wsgi (pid=4135): Target WSGI script '/Library/WebServer/Documents/favicon.ico' does not contain WSGI application 'application'.

任何帮助将不胜感激。

【问题讨论】:

  • 当我输入 $! 时,exec 格式错误消失了! python 在源文件的开头。我仍然不明白“脚本过早结束”错误或“目标 WSGI 脚本不包含 WSGI 应用程序'应用程序'。我已经验证了文件权限 (755) 和编码 (UTF-8)。
  • 你为什么把mod_python放在标题里?

标签: python osx-lion mod-wsgi web2py


【解决方案1】:

您将 WSGIScriptAlias 映射到 DocumentRoot 目录本身,并且目录上没有尾部斜杠,这可能意味着它试图以某种错误的方式将目录加载为 WSGI 脚本文件并且失败。脚本文件过早结束的消息令人困惑,除非您没有包含所有 mod_wsgi 配置。该消息表明您正在使用 mod_wsgi 守护程序模式(未显示),或者某些内容实际上被解释为 CGI 脚本。

无论如何,如果你想在 DocumentRoot 中删除 .py 文件,你可能想要做的是删除 WSGIScriptAlias 然后添加:

<Directory /Library/WebServer/Documents>
AddHandler wsgi-script .py
Options +ExecCGI
</Directory>

这意味着“http://192.168.1.2/test.py”应该可以工作,而且您仍然可以将其他静态文件放到该目录中,它们将被提供。

确保你去修改:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-19
    • 2012-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-06
    相关资源
    最近更新 更多