我最近发现 CGI 脚本几乎可以用任何可以打印到标准输出的语言编写。我写了一个小 guile cgi 脚本,它适用于我的本地 apache 安装,但不适用于我的共享主机:
#!/usr/local/bin/guile -s
!#
(display "Content-Type: text/html")
(newline)
(newline)
(display "hi")
(newline)
这是输出,当我通过 ssh 从主机上的 shell 运行脚本时:
$ ./scheme.cgi
Content-Type: text/html
hi
所以,显然我的主机已经安装了诡计。但是,当我尝试在浏览器中访问此文件时,我收到“500 内部服务器错误”。查看我的错误日志时,我发现我收到了可怕的“脚本头过早结束”错误:
[server.com] [Tue Aug 17 00:54:19 2010] [error] [client xx.xx.xx.xxx] (2)No such file or directory:
exec of '/home/www/vhosts/jcw.geekisp.com/cgi-bin/scheme.cgi' failed
[server.com] [Tue Aug 17 00:54:19 2010] [error] [client xx.xx.xx.xxx] Premature end
of script headers: scheme.cgi
因为我在共享主机上,所以使用 mod_lisp 或 guile 的 fastcgi 实现是不可能的。话虽这么说,这里可能是什么问题?我用 python、perl、ruby 和 sh 编写的类似 cgi 脚本在服务器上工作,没有错误。我看到主机上安装了 guile 1.8.7,但我的本地机器是最新版本。
我知道这是一个非常小众的问题,任何帮助将不胜感激!