执行格式错误:apache + Mac OS X Lion 上的 mod_wsgi
我正在尝试在运行 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 Internal Server”的响应错误。”
我的服务器日志显示:
[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'.
任何帮助将不胜感激。
I am trying to set up a web development environment using Python 2.7, apache, mod_wsgi, and web2py on an iMac running Lion (Mac OS X 10.7.3).
I downloaded and installed mod_wsgi v. 3.3 (./configure; make; sudo make install)
It installed in /usr/libexec/apache2. Everything looks sensible:
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
I added several configuration directives to /private/etc/apache2/httpd.conf after all the LoadModule directives.
LoadModule wsgi_module libexec/apache2/mod_wsgi.so
WSGIScriptAlias / /Library/WebServer/Documents
I restarted the apache daemon. The apache log looked good:
[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 configured -- resuming normal operations
I put this file into the /Library/WebServer/Documents folder:
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 executed it from my browser with: http://192.168.1.2/test.py
I got back a response of "500 Internal Server error."
My server log says:
[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'.
After much searching I haven't been able to find out why. I even stuck a favicon.ico in the documents folder. That caused this to be logged:
[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'.
Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将 WSGIScriptAlias 映射到 DocumentRoot 目录本身,并且目录上没有尾部斜杠,这可能意味着它正在尝试以某种错误的方式加载该目录作为 WSGI 脚本文件并失败。除非您没有包含所有 mod_wsgi 配置,否则脚本文件消息的过早结束会令人困惑。该消息表明您正在使用 mod_wsgi 守护进程模式(未显示),或者某些内容实际上被解释为 CGI 脚本。
不管怎样,如果你想在 DocumentRoot 中删除 .py 文件,你可能想要做的是删除 WSGIScriptAlias 然后添加:
这将意味着 'http://192.168.1.2/test.py' 应该可以工作,加上你仍然可以将其他静态文件放入该目录中,并且它们将被提供。
请务必修改:
http://code.google.com/p/modwsgi/wiki /快速配置指南
You mapped WSGIScriptAlias to DocumentRoot directory itself and without a trailing slash on the directory, which likely means that it is trying to load the directory in some bad way as the WSGI script file and failing. The premature end of script file message is confusing though unless you haven't included all your mod_wsgi configuration. That message indicates you are either using mod_wsgi daemon mode, which isn't shown, or something is actually being interpreted as a CGI script.
Anyway, what you probably want to do if you want to drop .py files in DocumentRoot is to do is remove the WSGIScriptAlias and then add:
This will mean 'http://192.168.1.2/test.py' should work, plus you can still drop other static files in that directory and they will be served up.
Make sure you go revise:
http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide