【问题标题】:Need apache to show unix directory需要apache来显示unix目录
【发布时间】:2013-02-21 12:45:34
【问题描述】:

我在 unixserverA 上运行 apache,我希望使用此 URL http://unixserverA/sg/hello.txt 在浏览器中查看 unix [/app1/bea/hello.txt] 上的文件

请帮助我需要在 httpd.conf 中进行哪些更改。

我在我的 httpd.conf 中包含了一个 conf 文件 [bulk.conf],并且该 bulk.conf 文件具有以下条目,但没有帮助。

ScriptAlias /sg/ "/app1/bea/"

以下是我在浏览器中看到的错误

内部服务器错误 服务器遇到内部错误或配置错误,无法完成您的请求。

请联系服务器管理员 user@unixserverA 并告知他们错误发生的时间,以及您所做的任何可能导致错误的事情。

服务器错误日志中可能会提供有关此错误的更多信息。

错误日志显示:

[Thu Feb 21 04:57:45 2013] [error] (2)No such file or directory: exec of '/appl/bea/hello.txt' failed
[Thu Feb 21 04:57:45 2013] [error] [client 109.71.70.209] 脚本头过早结束:hello.txt

【问题讨论】:

  • 为什么是ScriptAlias?您想显示静态文件还是运行脚本?无论如何,请按照错误消息建议并检查服务器错误日志。
  • 我想运行一个脚本。日志中的错误消息说 ....[Thu Feb 21 04:57:45 2013] [error] (2)No such file or directory: exec of '/appl/bea/hello.txt' failed [Thu Feb 21 04:57:45 2013] [错误] [客户端 109.71.70.209] 脚本头过早结束:hello.txt

标签: apache


【解决方案1】:

当您使用 ScriptAlias 指令时,您指示 Apache 将所选目录中的任何文件作为脚本或可执行文件处理。正如Apache Tutorial: Dynamic Content with CGI 解释的那样,此类脚本预计会为 HTTP 响应生成有效输出,包括 HTTP 标头。例如,有一个与 Apache 捆绑在一起的 printenv.pl 示例脚本:

#!/usr/bin/perl
##
##  printenv -- demo CGI program which just prints its environment
##

print "Content-type: text/plain; charset=iso-8859-1\n\n";
foreach $var (sort(keys(%ENV))) {
    $val = $ENV{$var};
    $val =~ s|\n|\\n|g;
    $val =~ s|"|\\"|g;
    print "${var}=\"${val}\"\n";
}

作为可执行文件,您也可以从控制台运行它:

./printenv.pl

我不知道hello.txt 包含什么,但*.txt 扩展表明它根本不是一个程序。如果它毕竟是一个程序,请确保:

  • 它至少打印一个Content-Type 标头和一个空行。
  • 它有可执行标志:chmod a+x hello.txt

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-22
    • 1970-01-01
    • 2012-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多