[英]Newbie Apache / Python error
Trying to configure apache on my laptop to execute a python script for a small assignment: 尝试在笔记本电脑上配置apache以执行python脚本进行小任务:
ScriptAlias /scripts/ /scripts/
在我的虚拟主机文件中,我添加了ScriptAlias /scripts/ /scripts/
Added directory handle also in my conf file: 在我的conf文件中也添加了目录句柄:
Options +ExecCGI FollowSymLinks Indexes MultiViews AllowOverride All Order allow,deny Allow from all AddHandler cgi-script .py 选项+ ExecCGI FollowSymLinks索引多视图AllowOverride所有订单允许,拒绝所有AddHandler cgi-script .py
The script I'm trying to run is (a sample python test script): 我要运行的脚本是(示例python测试脚本):
#!/usr/bin/python
print "Content-type: text/html"
print
print "<pre>"
import os, sys
from cgi import escape
print "<strong>Python %s</strong>" % sys.version
keys = os.environ.keys()
keys.sort()
for k in keys:
print "%s\t%s" % (escape(k), escape(os.environ[k]))
print "</pre>"
When I access it via http://127.0.0.1/scripts/results.py I get an Internal Server Error and in my error log I get the following error: 当我通过http://127.0.0.1/scripts/results.py访问它时,出现内部服务器错误,并且在错误日志中出现以下错误:
[Mon Dec 05 20:58:30 2011] [error] [client 127.0.0.1] (2)No such file or directory: exec of '/scripts/result.py' failed [2011年12月5日20:58:30星期一] [错误] [客户端127.0.0.1](2)无此文件或目录:“ / scripts / result.py”的exec失败
[Mon Dec 05 20:58:30 2011] [error] [client 127.0.0.1] Premature end of script headers: result.py [2011年12月5日20:58:30星期一] [错误] [客户端127.0.0.1]脚本标头的结尾过早:result.py
Apache does have suexec module loaded from what I've found when running apachectl -v, and suspect that this may have something to do with the problem. Apache确实从我在运行apachectl -v时发现的内容中加载了suexec模块,并怀疑这可能与问题有关。
Also running /usr/bin/python /scripts/result.py executes fine, but since apache runs under a different user guess this doesn't mean much. 同样运行/ usr / bin / python /scripts/result.py可以很好地执行,但是由于apache在不同的用户下运行,所以这并不意味着什么。
Also I'm running this on OSX Lion, and I wasn't able to find how to run the script from cli as apache, during my debugging. 另外,我也在OSX Lion上运行此脚本,并且在调试过程中找不到从cli作为apache运行脚本的方法。
Any help would be appreciated. 任何帮助,将不胜感激。
I don't have access to OSX, but I'd probably try something like this: 我没有OSX的访问权限,但我可能会尝试以下操作:
ScriptAlias /cgi-bin/ "/scripts/"
<Directory "/scripts">
Options +ExecCGI FollowSymLinks Indexes MultiViews
AllowOverride All
Order allow,deny
Allow from all
AddHandler cgi-script .py
</Directory>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.