Apache中的"标题之前的脚本输出结束"错误

 宫廷的围脖6uw_1911 发布于 2023-01-18 20:19

当我尝试访问我的Perl脚本时,Windows上的Apache给出了以下错误:

Server error!

The server encountered an internal error and was unable to complete your request.

Error message: 
End of script output before headers: sample.pl

If you think this is a server error, please contact the webmaster.

Error 500

localhost
Apache/2.4.4 (Win32) OpenSSL/1.0.1e PHP/5.5.3

这是我的示例脚本

#!"C:\xampp\perl\bin\perl.exe"
print "Hello World";

但不是在浏览器上工作

5 个回答
  • 在raspberry-pi上发生了相同的错误。我通过添加-wshebang来修复它

    #!/usr/bin/perl -w
    

    2023-01-18 20:21 回答
  • 可能这是SELinux块。尝试这个:

    # setsebool -P httpd_enable_cgi 1
    # chcon -R -t httpd_sys_script_exec_t cgi-bin/your_script.cgi
    

    2023-01-18 20:21 回答
  • 备查:

    这通常是您无法查看或执行文件时发生的错误,其原因通常是权限错误.我将首先关注@Renning的建议并运行chmod 755 test.cgi(显然用这里的cgi脚本替换test.cgi).

    如果这不起作用,您可以尝试其他一些事情.当我test.cgi在另一个用户的家中以root身份创建时,我曾遇到此错误.修复程序在那里运行chmod user:user test.cgi,其中user是您所在的用户的名称.

    我能想到的最后一件事是确保你的cgi脚本返回正确的标题.在我的ruby脚本中,我通过puts "Content-type: text/html"在实际输出任何内容之前放入页面.

    快乐的编码!

    2023-01-18 20:21 回答
  • 检查文件权限.

    我在设置了错误权限的Linux机器上遇到了完全相同的错误.

    chmod 755 myfile.pl

    解决了这个问题.

    2023-01-18 20:21 回答
  • 如果这是Web的CGI脚本,那么您必须输出标题:

    #!"C:\xampp\perl\bin\perl.exe"
    
    print "Content-Type: text/html\n\n";
    print "Hello World";
    

    以下错误消息告诉您这一点 End of script output before headers: sample.pl

    或者甚至更好,使用CGI模块输出标题:

    #!"C:\xampp\perl\bin\perl.exe"
    
    use strict;
    use warnings;
    
    use CGI;
    
    print CGI::header();
    print "Hello World";
    

    2023-01-18 20:23 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有