python – 执行格式错误:Mac OS X Lion上的apache 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] [通知] 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'.
任何帮助,将不胜感激.
解决方法:
您将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
标签:python,osx-lion,mod-wsgi,web2py 来源: https://codeday.me/bug/20190709/1416590.html