The specified CGI application misbehaved by not returning a complete set of HTTP headers

本文档介绍了在Windows Server 2019上部署华为云服务时遇到HTTP 502 Bad Gateway错误的解决方法。错误原因是CGI应用程序未返回完整HTTP头。解决方案包括:1) 安装微软VC Redist x64;2) 设置服务器显示详细错误;3) 关闭php.ini中的cgi.force_redirect选项以允许PHP CGI脚本直接访问。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天部署华为云,提示如下错误:
HTTP Error 502.2 - Bad Gateway
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are "<b>Security Alert!</b> The PHP CGI cannot be accessed directly. <p>This PHP CGI binary was compiled with force-cgi-redirect enabled. This means that a page will only be served up if the REDIRECT_STATUS CGI variable is set, e.g. via an Apache Action directive.</p> <p>For more information as to <i>why</i> this behaviour exists, see the <a href="http://php.net/security.cgi-bin">manual page for CGI security</a>.</p> <p>For more information about changing this behaviour or re-enabling this webserver, consult the installation file that came with this distribution, or visit <a href="http://php.net/install.windows">the manual page</a>.</p> ".
-----------------------------
大意是说指定的 CGI 应用程序由于未返回完整的一组 HTTP 头而产生错误行为。
-----------------------------
服务器:
系统:Microsoft Windows Server 2019 Datacenter
版本:10.0.17763 N/A Build 17763
-----------------------------
解决方案:
一、微软下载安装 vc_redist.x64.exe 包:
    https://learn.microsoft.com/en-US/cpp/windows/latest-supported-vc-redist?view=msvc-170
-----------------------------
二、设置服务器显示详细错误:
<system.web>
    <customErrors mode="Off" />
</system.web>
<system.webServer>
    <httpErrors errorMode="Detailed" />
</system.webServer>
-----------------------------
三、关闭 php.ini 中的强制重定向项(它可以防止当PHP运行的CGI脚本未经验证的访问)
    cgi.force_redirect = 0
    
    官方描述:
    cgi.force_redirect bool
    cgi.force_redirect is necessary to provide security running PHP as a CGI under most web servers. Left undefined, PHP turns this on by default. You can turn it off at your own risk.
    Note:
    Windows Users: When using IIS this option must be turned off. For OmniHTTPD or Xitami the same applies.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值