500 内部服务器错误(在 ubuntu 上工作)

500 内部服务器错误(在 ubuntu 上工作)

我将 printenv.pl 文件复制到/usr/lib/cgi-bin并运行:

chmod +rx printenv.pl

在我的apache2.conf文件中,我添加了以下几行:

<Files ~ "\.pl$">
    Options +ExecCGI
</Files>

AddHandler cgi-script .pl

并重新启动 Apache 服务器:

/etc/init.d/apache2 start

但当我去http://localhost/cgi-bin/printenv.pl我收到以下错误:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.

Apache/2.2.17 (Ubuntu) Server at localhost Port 80

这是我的错误日志文件:

[Thu Jul 28 19:28:43 2011] [error] [client 127.0.0.1] (2)No such file or directory: exec of '/usr/lib/cgi-bin/printenv.pl' failed
[Thu Jul 28 19:28:43 2011] [error] [client 127.0.0.1] Premature end of script headers: printenv.pl

但这就是我的/usr/lib/cgi-bin目录如下所示:

/usr/lib/cgi-bin$ ls -l
total 8
-rwxr-xr-x 1 root root 331 2011-07-28 19:01 printenv.pl
-rwxr-xr-x 1 root root 335 2011-07-28 18:50 printenv.pl~

你能帮我解决这个问题吗?谢谢!

答案1

仔细检查脚本的第一行。

如果该行不以 开头,#!或者 perl 安装在与 后面的路径不同的位置#!(例如,/usr/local/bin/perlvs /usr/bin/perl),那么您将收到该错误。

如果 perl 的路径看起来正确,并且您已经从 Windows 机器复制了脚本,那么您可能会被行末的回车符绊倒。

您可以用它来验证行尾cat -v /usr/lib/cgi-bin/printenv.pl | head -1没有。^M

如果有,您可以使用perl -pi.bak -e 's/\r+$//' /usr/lib/cgi-bin/printenv.pl将其删除。

相关内容