IIS 10 error when .html pages requested from browser(指定的 CGI 应用程序遇到错误)

IIS 10 error when .html pages requested from browser(The specified CGI application encountered an error)

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

我正在尝试在 Windows 服务器 2019 上的新 IIS 10 安装上重建网站。(该网站在 Windows2008R2 测试盒上运行良好。)当我去的时候在浏览器中请求 index.html 我收到一条错误消息 "The specified CGI application encountered an error and the server terminated the process." 当我将页面重命名为 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>

您是否正确设置了处理程序?我们总是为 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>