【问题标题】:Newbie Apache / Python error新手 Apache / Python 错误
【发布时间】:2012-01-13 17:54:36
【问题描述】:

尝试在我的笔记本电脑上配置 apache 来执行一个小任务的 python 脚本:

  • 我在根目录下创建了一个 /scripts 文件夹,并授予它所有权限 777。
  • 在我的虚拟主机文件中我添加了ScriptAlias /scripts/ /scripts/
  • 在我的 conf 文件中也添加了目录句柄:

    选项 +ExecCGI FollowSymLinks 索引 MultiViews 允许覆盖所有 命令允许,拒绝 允许所有人 AddHandler cgi脚本.py

我正在尝试运行的脚本是(示例 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>"

当我通过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

[Mon Dec 05 20:58:30 2011] [error] [client 127.0.0.1] 脚本头过早结束:result.py

Apache 确实从我在运行 apachectl -v 时发现的内容中加载了 suexec 模块,并且怀疑这可能与问题有关。

同样运行 /usr/bin/python /scripts/result.py 执行得很好,但是由于 apache 在不同的用户下运行,猜测这并不意味着什么。

我也在 OSX Lion 上运行它,但在调试期间我无法找到如何从 cli 作为 apache 运行脚本。

任何帮助将不胜感激。

【问题讨论】:

  • 你找到答案了吗?

标签: python macos apache


【解决方案1】:

我无法访问 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>

【讨论】:

    猜你喜欢
    • 2012-10-18
    • 1970-01-01
    • 2015-03-13
    • 1970-01-01
    • 2011-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-29
    相关资源
    最近更新 更多