【问题标题】:IIS 10 error when .html pages requested from browser(The specified CGI application encountered an error)从浏览器请求 .html 页面时出现 IIS 10 错误(指定的 CGI 应用程序遇到错误)
【发布时间】:2020-04-13 23:00:02
【问题描述】:

从浏览器请求 .html 页面时出现 IIS 10 错误(指定的 CGI 应用程序遇到错误)

我正在尝试在 Windows server 2019 上的新 IIS 10 安装上重建网站。(这是一个在 Windows2008R2 测试盒上运行良好的网站。)当我进入浏览器并请求 index.html 时,我得到一个错误消息“指定的 CGI 应用程序遇到错误,服务器终止了进程。”当我将页面重命名为 index.htm 时,它可以工作。

浏览器控制台中的错误提示:未声明 HTML 文档的字符编码。如果文档包含 US-ASCII 范围之外的字符,则文档将在某些浏览器配置中呈现乱码。页面的字符编码必须在文档或传输协议中声明。

但页面字符编码已正确声明并在另一台服务器上运行良好。

我的 web.config 如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <httpProtocol>
            <customHeaders>
                <add name="X-XSS-Protection" value="1; mode=block" />
            </customHeaders>
        </httpProtocol>
        <handlers>
            <clear />
            <add name="PHP" path="*.html,*.php" verb="*" type="" modules="FastCgiModule" scriptProcessor="C:\PHP\php-cgi.exe" resourceType="File" requireAccess="Script" allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
            <add name="HTMLPHPMapping" path="*.html" verb="*" type="" modules="CgiModule" scriptProcessor="C:\php7\php-cgi.exe" resourceType="File" requireAccess="Script" allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
            <add name="PHP74Mapping" path="*.php" verb="*" type="" modules="FastCgiModule" scriptProcessor="C:\php7\php-cgi.exe" resourceType="File" requireAccess="Script" allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
            <add name="CGI-exe" path="*.exe" verb="*" type="" modules="CgiModule" scriptProcessor="" resourceType="File" requireAccess="Execute" allowPathInfo="true" preCondition="" responseBufferLimit="4194304" />
            <add name="TRACEVerbHandler" path="*" verb="TRACE" type="" modules="ProtocolSupportModule" scriptProcessor="" resourceType="Unspecified" requireAccess="None" allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
            <add name="OPTIONSVerbHandler" path="*" verb="OPTIONS" type="" modules="ProtocolSupportModule" scriptProcessor="" resourceType="Unspecified" requireAccess="None" allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
            <add name="StaticFile" path="*" verb="*" type="" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" scriptProcessor="" resourceType="Either" requireAccess="Read" allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
        </handlers>
        <httpErrors errorMode="Custom" defaultResponseMode="File">
            <clear />
            <error statusCode="500" path="index.html" />
            <error statusCode="404" path="index.html" />
        </httpErrors>
        <defaultDocument>
            <files>
                <clear />
                <add value="index.html" />
                <add value="Default.htm" />
                <add value="Default.asp" />
                <add value="index.htm" />
                <add value="iisstart.htm" />
            </files>
        </defaultDocument>
        <security>
            <requestFiltering>
                <fileExtensions>
                    <add fileExtension=".html" allowed="true" />
                </fileExtensions>
            </requestFiltering>
        </security>
    </system.webServer>
</configuration>

【问题讨论】:

  • 1) PHP 不需要那么多处理程序。只要第一个就足够了。 2) docs.microsoft.com/en-us/iis/troubleshoot/… 使用 FRT 了解更多关于 CGI 错误的信息。您可以编辑问题以包含 FRT 日志的重要部分。
  • 感谢 Lex Li,我会这样做并恢复。我想知道为什么我看不到错误日志。

标签: html iis cgi config


【解决方案1】:

您是否正确设置了处理程序?我们总是为 PHP cgi 创建模块映射,例如 这个。

        <handlers>
            <clear />
            <add name="phpmaphtml" path="*.html" verb="*" modules="FastCgiModule" scriptProcessor="C:\Program Files\PHP\v7.3.9\php-cgi.exe" resourceType="File" />
        </handlers>

【讨论】:

  • 谢谢!这是工作。这些映射搞砸了一切。
  • @dupnic。我很高兴我的回复能帮上忙。如果您能接受它作为答案,那就太好了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-11-04
  • 1970-01-01
  • 2018-05-17
  • 2020-10-10
  • 2018-02-23
  • 2021-01-10
  • 2022-12-11
相关资源
最近更新 更多