【发布时间】:2015-03-11 13:36:40
【问题描述】:
我想我犯了一些愚蠢的错误,但我无法找到它。 试图在 apache 网络服务器上运行一个简单的 python cgi 脚本。我的代码是
#/usr/bin/env python
import cgitb
import cgi
cgitb.enable()
print 'Content-Type: text/html'
print
print '<html>'
print '<head><title>My first Python CGI app</title></head>'
print ' <body>'
print ' <p>something to try<p>'
print ' </body>'
print '</html>'
这段代码在 /usr/lib/cgi-bin 我试图通过 localhost/cgi-bin/test.py 运行它 但它显示 500 INTERNAL SERVER ERROR。 我尝试更改其权限,但没有任何反应。 我能够从 /var/www/html/file_name.html 运行 html 文件 所以我尝试将它移动到 www/ 和 www/html/ (在两者中),并制作 cgi-bin 文件夹,没有它,什么都没有解决。
我在 apache2.conf 中添加了这个
<Directory /usr/lib/cgi-bin>
Options +ExecCGI
AddHandler cgi-script .cgi .py
Order allow,deny
Allow from all
</Directory>
和 var/log/apache2/error.log 说
[2015 年 1 月 13 日星期二 22:54:11.422641] [cgid:error] [pid 10157:tid 140434248509184]
[client 127.0.0.1:44941] 头文件前的脚本输出结束:test.py
[2015 年 1 月 14 日星期三 00:20:24.434351] [cgid:error] [pid 26512:tid 140434573543296
(8)Exec format error: AH01241: exec of '/usr/lib/cgi-bin/test.py' failed
[2015 年 1 月 14 日星期三 00:20:24.434778] [cgid:error] [pid 10158:tid 140434456491776]
[client 127.0.0.1:45974] 头文件前的脚本输出结束:test.py
【问题讨论】:
-
首先需要打印出内容类型(print 'Content-Type: text/html'; print);如果这不起作用,您应该发布您的 apache 配置
-
没用。你的意思是apache2.conf吗?
-
是的,或者您正在配置 apache 以使用 cgi(另外,/var/log/httpd/error.log(或类似的)是否提供更多详细信息?)
-
我在我的问题中添加了更多细节。什么?
-
你有一个错字;有关更多详细信息和提示,请参阅我的答案。