6

我最近发现 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,但我的本地机器是最新版本。

我知道这是一个非常小众的问题,任何帮助将不胜感激!

4

3 回答 3

6

您也许还可以编译自己的 guile 或诸如此类的副本并将其存储在您的 ~/bin/ 目录中,并让脚本指向那里。

于 2010-08-21T20:21:02.530 回答
4

I believe that error means your web server process doesn't have access to the /usr/local/bin/guile interpreter. Check the permissions on that file, make sure it is accessible if the server runs in a chroot or under mandatory access control, etc. And double-check the permissions on your script while you're at it.

于 2010-08-17T19:52:21.423 回答
1

事实证明,当我在服务器上 ssh'ed 时存在的 /usr/local/bin 目录与通过浏览器提供和访问脚本时的 /usr/local/bin 不同。我通过这个 CGI 脚本发现了哪些解释器可用:

#!/bin/sh
echo "Content type: text/html\r\n\r\n"
echo "ls /usr/local/bin"

当我通过浏览器运行这个脚本时,我发现列出了 mzscheme,但没有列出 guile。所以,问题解决了,我正在使用 mzscheme。

谢谢,卡尔。

于 2010-08-19T14:19:23.480 回答