【问题标题】:How to set up shared `system.webServer` settings for all sites on an IIS server如何为 IIS 服务器上的所有站点设置共享的“system.webServer”设置
【发布时间】:2013-05-08 16:44:19
【问题描述】:

我正在我们的托管环境中设置一个新的网络服务器。这是一个只能由我们使用的新虚拟机,所以我可以用它做我想做的事(在合理范围内)。它在 Windows 2008 R2 上运行 IIS 7,系统上安装了 ASP.Net 4.0。

我很想强制服务器上的所有站点使用以下 system.webServer 设置,除非它们被明确覆盖,但将它们添加到 Framework config folders 中的 Machine.config or Web.config 文件中(均为 32 位和 64 位版本)似乎没有任何效果。

我试图强制的设置如下。我知道这些设置在单个站点的 Web.config 中可以正常工作(因为我已经从我自己配置​​的生产站点复制/粘贴了它们)并且我知道肯定安装了 IIS URL Rewrite Module 2

<system.webServer>
    <httpProtocol>
        <customHeaders>
            <remove name="X-Powered-By"/>
        </customHeaders>
    </httpProtocol>
    <staticContent>
        <remove fileExtension=".air"/>
        <remove fileExtension=".svg"/>
        <remove fileExtension=".ttf"/>
        <remove fileExtension=".otf"/>
        <remove fileExtension=".woff"/>
        <remove fileExtension=".eot"/>
        <mimeMap fileExtension=".air" mimeType="application/vnd.adobe.air-application-installer-package+zip"/>
        <mimeMap fileExtension=".svg" mimeType="image/svg+xml"/>
        <mimeMap fileExtension=".ttf" mimeType="application/x-font-truetype"/>
        <mimeMap fileExtension=".otf" mimeType="application/x-font-opentype"/>
        <mimeMap fileExtension=".woff" mimeType="application/x-font-woff"/>
        <mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject"/>
    </staticContent>
    <rewrite>
        <outboundRules>
            <rule name="Remove RESPONSE_Server">
                <match serverVariable="RESPONSE_Server" pattern=".+"/>
                <action type="Rewrite" value=""/>
            </rule>
        </outboundRules>
    </rewrite>
</system.webServer>

这些设置应该意味着X-Powered-By: HTTP 标头不存在并且Server: 标头为空,但是当我对此进行测试时,我得到以下信息:

[12:35:56] owen@plum:~$ curl -I http://new.server.ip
HTTP/1.1 200 OK
Content-Length: 689
Content-Type: text/html
Last-Modified: Mon, 13 May 2013 15:11:24 GMT
Accept-Ranges: bytes
ETag: "2ce2122ec4fce1:0"
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Tue, 14 May 2013 11:36:16 GMT

我是否遗漏了一些明显的东西?难道只是system.webServer部分不能从这些默认配置文件中继承?

【问题讨论】:

  • 试试 ALL_CAPS 吗? ServerVariables 一般都是大写的。
  • 不,摘录不是问题,正如我在问题中提到的,这是我知道在其他地方工作的配置摘录。 (不,HTTP 中的标头不是 ALL_CAPS,只是当我们从 ASP 或 ASP.Net 访问它们时。)

标签: asp.net iis hosting machine.config


【解决方案1】:

Serverfault 看到这个问题。看来您可以从 C:\WINDOWS\system32\inetsrv\config 中的 applicationHost.config 文件指定 IIS 范围的重写规则。然后允许通过 IIS 管理和继承规则。

编辑:好的,这不起作用...尝试what's recommended here,看看这是否会有所不同(强制所有模块为所有请求运行可能会强制重写器正确获取继承的重写设置)。

【讨论】:

  • 恐怕也没有什么不同。
  • 作为记录,您还建议我检查C:\Windows\SysWOW64\inetsrv\Config中的同一文件,但这似乎也无法解决问题。
  • applicationHost.config 中没有&lt;modules/&gt; 部分;将该属性添加到 &lt;globalModules/&gt; 节点没有任何区别。 (而且,有趣的是,每次我编辑 system32 applicationHost.config 时,IIS 都会对 SysWOW64 进行相同的编辑。)
猜你喜欢
  • 2011-06-23
  • 1970-01-01
  • 1970-01-01
  • 2018-04-12
  • 1970-01-01
  • 1970-01-01
  • 2011-04-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多