Apache不通过浏览器处理python脚本(* .py)

编辑:OS是CentOS 5

我安装了Python 2.5.5,并试图通过浏览器运行一些Python脚本。

老实说,我以前没有用过Python。 我试图加载python模块到Apache,但它已经加载并被跳过。 我也证实我可以从我的命令行运行python脚本,如果我让他们可执行。

但是,当我把“ http://www.example.com/test.py ”放入我的浏览器时,它会返回未parsing的HTML,如下所示:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>500 Internal Server Error</title> </head><body> <h1>Internal Server Error</h1> <p>The server encountered an internal error or misconfiguration and was unable to complete your request.</p> <p>Please contact the server administrator, root@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.</p> <p>More information about this error may be available in the server error log.</p> <hr> <address>Apache/2.2.3 (CentOS) Server at www.example.com Port 80</address> </body></html> 

我的httpd.conf文件中也有以下内容。

 AddHandler cgi-script .py 

我很难过,因为我不知道从哪里看这里。 这是否为任何人敲响了钟声? 希望不要太明显,我在这里俯瞰…

先谢谢你。

编辑:在Apache error_log中find以下内容。

 [Fri Feb 26 19:58:38 2010] [error] [client xxx.xxx.xxx.xxx] (13)Permission denied: exec of 'test.py' failed [Fri Feb 26 19:58:38 2010] [error] [client xxx.xxx.xxx.xxx] Premature end of script headers: test.py [Fri Feb 26 20:04:56 2010] [notice] mod_python: Creating 4 session mutexes based on 256 max processes and 0 max threads. 

来自apache的错误13表示文件系统权限问题。
SElinux是否启用? (“ls -laZ test.py”的输出是什么)

我怀疑这是ScriptAlias或AddHandler / ExecCGI(其中任何一个都会得到apache来执行脚本)的问题 – 因为你得到一个500错误,而不是python源码apache显然是试图执行该文件。

我只使用mod_python进行Trac安装,他们为他们的应用程序提供相当明确的说明 。

然而,当我们testingmod_python的时候,我发现这篇文章很有帮助 – 你也可以。

Apache只会执行位于指定cgi-bin目录中的文件。 其他一切都被视为传递给观众的内容。 您的根目录不是,也不应该被标记为这样。

使用ScriptAlias <url-path> <directory>指令来设置你的cgi-bin目录。 例如: ScriptAlias /cgi-bin/ /webroot/cgi-bin/ 。 在那里复制您的脚本,然后致电http://www.example.com/cgi-bin/test.py 。 这应该适合你。