CGI应用未返回完整HTTP头错误的成因与解决
这是一个常见的错误报告:
The specified CGI application misbehaved by not returning a complete set of HTTP headers
其含义是:基于HTTP协议的CGI模式运行出现异常。
若问题源于Perl脚本,通常是因为第一行的shebang语句中不支持 -wT 参数。解决方法是将所有的 -wT 替换为 -w。
具体操作即:将 #!/usr/bin/perl –wT 修改为 #!/usr/bin/perl –w。
如果提示代表PHP以CGI模式运行,可在 php.ini 配置文件中找到 cgi.force_redirect(原文误写为gi.force_redirect),去掉前面的分号注释,并将值设置为 0。
完成上述配置后再次运行即可,这是针对PHP另一种运行模式的常见配置方法。
以下是今天遇到的一个具体PHP错误案例。
错误类型显示为:CGI Error
详细信息为:The specified CGI application misbehaved by not returning a complete set of HTTP headers.
最终的解决办法是将PHP的运行方式从CGI改为ISAPI方式。
测试环境为:Windows XP SP3 + IIS 5.1 + ActivePerl 5.10.0。
在安装并配置BugZilla后,运行CGI脚本时出现如下错误:
CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:
"-T" is on the #! line, it must also be used on the command line at E:\bugzilla-3.4.2\bugzilla-3.4.2\index.cgi line 1.
另一个类似的错误报告:
The specified CGI application misbehaved by not returning a complete set of HTTP headers
意思是:(http协议的CGI模式运行不正确)
因为perl脚本的第一句中不支持 -wT 参数,将所有的 -wT 替换成 -w 即可
即:将 #!/usr/bin/perl –wT 替换为:将 #!/usr/bin/perl –w
这是代表php是以CGI模试运行的 在php.ini找到 gi.force_redirect 把前面的分号去掉 把值改成0就行了。
PS:另外解决办法
修改IIS设置里,主目录选项卡->应用程序设置->选择CGI,之后在添加/编辑应用程序扩展映射名:将CGI可执行文件名写为:
D:\Perl\bin\perl.exe -x -wT “%s“ %s
(注:这里我的Perl安装在D:\Perl目录里)
这个样子就不需要更改BUGZilla的文件了