我们正在尝试重写“主机”标题给定标题为“X-CF-ORIGIN” - 这在本地工作,但是,在应用服务中,所有日志记录表明它已经工作但我们似乎没有看到效果。
我们希望错误的HOST标头出现500错误,但是,网站会解析,就好像主机标头没有被更改一样。
此外,我们的XDT转换表明它已经有效(见下文)。
This was initially raised on Kudu Github但已针对Azure App Service IIS提问。
代码示例: https://github.com/Workshop2/webforms-host-header-rewrite-spike
直播示例: 使用XDT转换http://webforms-fun.azurewebsites.net/
我们的重写规则:
<rule name="CDN Host Header Rewrite" stopProcessing="false">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{HTTP_X_CF_ORIGIN}" pattern="(.+)" />
</conditions>
<serverVariables>
<set name="HTTP_HOST" value="{C:1}" />
</serverVariables>
<action type="None" />
</rule>
我们的XDT转换:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<rewrite>
<allowedServerVariables>
<add name="HTTP_HOST" xdt:Transform="InsertIfMissing" />
</allowedServerVariables>
</rewrite>
</system.webServer>
</configuration>
applicationHost(通过IIS Manager找到):
<rewrite>
<allowedServerVariables>
<add name="HTTP_HOST" />
</allowedServerVariables>
<globalRules />
<outboundRules />
<providers />
<rewriteMaps />
<rules />
</rewrite>
请求跟踪失败:
测试
如果我创建一个测试规则来证明HTTP_HOST正在被更改,它会通过X-CF-ORIGIN标头正确使用HTTP_HOST数据集:
<rule name="test" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{HTTP_X_CF_ORIGIN}" pattern=".+" />
<add input="{HTTP_HOST}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="http://some-site.com/{C:1}" redirectType="Temporary" />
</rule>
请帮助 - 我们错过了什么?
答案 0 :(得分:1)
我发现Azure不喜欢设置 HTTP_HOST 服务器变量。如果您使用 HTTP_DISGUISED_HOST
,它可以正常工作在重写规则中更改此行:
<set name="HTTP_HOST" value="{C:1}" />
到此:
<set name="HTTP_DISGUISED_HOST" value="{C:1}" />
在applicationHost.xdt中更改此行:
<add name="HTTP_HOST" xdt:Transform="InsertIfMissing" />
到此:
<add name="HTTP_DISGUISED_HOST" xdt:Transform="InsertIfMissing" />