【问题标题】:Apache / XAMPP for Windows incorrectly treats file as executableApache / XAMPP for Windows 错误地将文件视为可执行文件
【发布时间】:2013-07-14 08:32:21
【问题描述】:

我在我的开发机器上运行XAMPP 1.8.1Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7 来测试我的项目。在我的私人项目和众所周知的 Bootstrap Datepicker 组件中,我可以选择任何语言(在 datepicker 的情况下为 38 种语言之一)但不能选择波兰语

经过深入调查,我发现这是由于当浏览器尝试加载语言环境文件时(general.pl.json,在我的项目中,bootstrap-datepicker.pl.js,在 Bootstrap Datepicker 的情况下),服务器(Apache)失败500 Internal Server Error

在分析 Apache error.log 文件后,我发现这是发生的,因为 Apache 以某种方式试图将该文件作为(可能是 Perl)可执行脚本执行:

[win32:error] [pid 5128:tid 1680] [client 127.0.0.1:53455] AH02102: C:/XAMPP/htdocs/mobile/public/pg-demo-bootstrap/locales/general.pl.json is not executable; ensure interpreted scripts have "#!" or "'!" first line, referer: http://127.0.0.1/mobile/public/pg-demo-bootstrap/
[cgi:error] [pid 5128:tid 1680] (9)Bad file descriptor: [client 127.0.0.1:53455] AH01222: don't know how to spawn child process: C:/XAMPP/htdocs/mobile/public/pg-demo-bootstrap/locales/general.pl.json, referer: http://127.0.0.1/mobile/public/pg-demo-bootstrap/
[win32:error] [pid 5128:tid 1644] [client 127.0.0.1:53465] AH02102: C:/XAMPP/htdocs/us/ustv/assets/6dafd2fe/js/locales/bootstrap-datepicker.pl.js is not executable; ensure interpreted scripts have "#!" or "'!" first line, referer: http://127.0.0.1/us/ustv/content/manage/update.html?id=4
[cgi:error] [pid 5128:tid 1644] (9)Bad file descriptor: [client 127.0.0.1:53465] AH01222: don't know how to spawn child process: C:/XAMPP/htdocs/us/ustv/assets/6dafd2fe/js/locales/bootstrap-datepicker.pl.js, referer: http://127.0.0.1/us/ustv/content/manage/update.html?id=4

我做了很多更改内容和文件名的测试,使用许多假文件来假装这个文件(波兰语语言环境),这一切都带来了结论,那个内容不是问题,只有文件名中的.pl 有问题。

好问题是:

  1. 为什么 Apache 声称,这是脚本,虽然 .pl(Perl?)文件名的一部分在中间,而且文件名实际上以 .js.json 结尾?

  2. 为什么 Apache for Windows 尝试执行 Linux/Unix/Bash 脚本并在其第一行中寻找 #!'! 字符?

更好的问题是,如何解决这个问题,以便 Apache 开始将此文件视为简单的 Javascript,就像所有其他语言环境文件一样?并且不会尝试执行它?

【问题讨论】:

    标签: javascript apache xampp executable


    【解决方案1】:

    在xampp\apache\conf\httpd.conf中,应该有这样一行:

    AddHandler cgi-script .cgi .pl .asp
    

    像这样简单地注释掉这一行:

    #AddHandler cgi-script .cgi .pl .asp
    

    并重新启动 Apache。如果您想保留 .cgi 和 .asp 处理程序,只需从该行中删除 .pl。即使您这样做,Perl 实际上仍然可以工作。

    【讨论】:

    • 这解决了问题,所以我会接受你的回答并奖励你来之不易的赏金。然而,这并没有回答这个问题——为什么 Apache 对带有 .pl.js.pl.json 扩展名的文件产生这些问题?上一行确实严格说明了.pl 扩展文件。这似乎是一个错误。
    【解决方案2】:

    我遇到了同样的问题,之前的答案并没有为我解决问题,但将我带到了http://httpd.apache.org/docs/2.2/mod/mod_mime.html#addhandler 的 Apache 文档,上面写着:

    文件名可能有multiple extensions 并且扩展参数将 与它们中的每一个进行比较。

    multiple extensions 链接指向同一页面上的另一个部分,该部分说明文件可以具有多个扩展名。即:welcome.fr.html 被视为与welcome.html.fr 相同。扩展名的顺序无关紧要,文件名甚至可以包含多种语言,如welcome.html.en.de。优点是定义的语言在 HTTP 标头中发送。

    仅基于最终扩展配置处理程序:

    <FilesMatch \.pl$>
    SetHandler cgi-script pl
    </FilesMatch>
    

    为了完成这项工作,我必须首先删除 pl 的处理程序:

    RemoveHandler pl
    

    【讨论】:

      【解决方案3】:

      如果 apache 日志中出现以下消息

      apache:.js 不可执行;确保解释的脚本有“#!”

      您应该修改配置文件并使用 Alias 而不是 ScriptAlias,如下所示:

      别名 /bugzilla/ "C:/bugzilla/"

      并在别名行之后的apache配置中添加以下sn-p。

      <Directory "C:/bugzilla">
          ScriptInterpreterSource Registry-Strict
          AddHandler cgi-script .cgi
          Options +ExecCGI +FollowSymLinks
          DirectoryIndex index.cgi index.html
          AllowOverride Limit FileInfo Indexes Options AuthConfig
          Require all granted
      </Directory>
      

      【讨论】:

      • 请更正答案的格式和内容,因为目前它几乎完全不可读。
      • @trejder 我已经更正了格式和内容,现在可以阅读了,这个答案有帮助吗?
      • 好的,谢谢。我赞成你的回答,因为现在一切都清楚了。
      猜你喜欢
      • 2014-06-03
      • 1970-01-01
      • 1970-01-01
      • 2014-08-07
      • 1970-01-01
      • 2019-05-20
      • 1970-01-01
      • 1970-01-01
      • 2016-03-07
      相关资源
      最近更新 更多