【问题标题】:Azure App Service applicationHost.xdt appears to have no effectAzure App Service applicationHost.xdt 似乎没有效果
【发布时间】:2019-05-14 16:14:33
【问题描述】:

我正在尝试使用 Azure 网站设置反向代理,大致遵循 this guide 说明如何在此类网站上修改 ApplicationHost.config - 但它对我不起作用。

我有这个 applicationHost.xdt:

<?xml version="1.0"?>  
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">  
    <system.webServer>
        <proxy xdt:Transform="InsertIfMissing" enabled="true" preserveHostHeader="false" reverseRewriteHostInResponseHeaders="false" />
        <rewrite>
            <allowedServerVariables>
                <add name="HTTP_X_ORIGINAL_HOST" xdt:Transform="InsertIfMissing" />
                <add name="HTTP_X_UNPROXIED_URL" xdt:Transform="InsertIfMissing" />
                <add name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" xdt:Transform="InsertIfMissing" />
                <add name="HTTP_ACCEPT_ENCODING" xdt:Transform="InsertIfMissing" />
            </allowedServerVariables>
        </rewrite>
    </system.webServer>
</configuration>

我把它放在我的网络应用程序的site 目录中。

转换似乎已被执行(来自转换日志):

2017-09-06T12:12:20 StartSection Executing InsertIfMissing (transform line 8, 50)
2017-09-06T12:12:20 on /configuration/system.webServer/rewrite/allowedServerVariables/add
2017-09-06T12:12:20 Applying to 'allowedServerVariables' element (no source line info)
2017-09-06T12:12:20 EndSection Done executing InsertIfMissing

我确实有四个这样的积木。

通过重写设置标题我仍然得到 500 秒。详细的错误消息包含以下内容:

<h3>HTTP Error 500.50 - URL Rewrite Module Error.</h3> 
<h4>The server variable &quot;HTTP_X_UNPROXIED_URL&quot; is not allowed to be set. Add the server variable name to the allowed server variable list.</h4>

目前不知道该怎么做。有什么想法吗?

【问题讨论】:

  • 请以github.com/projectkudu/kudu/wiki/…开头,并确定您的问题是在第二个还是第三个桶中。
  • 我已经使用该资源了 - 谢谢。我不知道如何查看生成的applicationhost.config

标签: azure azure-web-app-service


【解决方案1】:

我在 TomSSL article、@David Ebbo 的 comment 上遇到了同样的问题,最终让我得到了答案,但我觉得值得添加它以节省人们一些时间。这是因为 applicationHost.config 缺少xdt:Locator="Match(name)":

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <system.webServer>
        <proxy xdt:Transform="InsertIfMissing" enabled="true" preserveHostHeader="false" reverseRewriteHostInResponseHeaders="false"/>
        <rewrite xdt:Transform="InsertIfMissing">
            <allowedServerVariables xdt:Transform="InsertIfMissing">
                <add name="HTTP_X_ORIGINAL_HOST" xdt:Transform="InsertIfMissing" xdt:Locator="Match(name)"/>
                <add name="HTTP_X_UNPROXIED_URL" xdt:Transform="InsertIfMissing" xdt:Locator="Match(name)"/>
                <add name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" xdt:Transform="InsertIfMissing" xdt:Locator="Match(name)"/>
                <add name="HTTP_ACCEPT_ENCODING" xdt:Transform="InsertIfMissing" xdt:Locator="Match(name)"/>
            </allowedServerVariables>
        </rewrite>
    </system.webServer>
</configuration>  

【讨论】:

  • 对于任何看到这个的人,请确保使用带有大写 L 的“xdt:Locator”。答案中写的小写版本不会有效果。
  • 抱歉,我使用原始文章中的评论来获取我认为更正后的 applicationHost.config 而不是我实际使用的配置。我已经纠正了上面的情况。
  • 没问题。感谢您修复。我只是想节省其他人头疼的时间,试图找出问题所在。我终于使用此工具对基础 applicationhost.config 应用补丁进行故障排除:webconfigtransformationtester.apphb.com
【解决方案2】:

调查这些问题的关键是确定问题是由于转换没有做正确的事情,还是 applicationhost.config 没有按预期工作。

您可以从 Kudu 控制台查看 D:\local\Config 中生成的 applicationhost.config。

更多详情请参阅this page

【讨论】:

  • 我现在已经检查了几次,发布 applicationHost.xdt 可以在我的主插槽上运行,但在我的开发插槽上没有发生任何转换。 xdt 是相同的,我将它放在相同的位置,但即使在重新启动应用程序后也不会创建转换日志文件夹。我得到的 500 是访问被拒绝,试图访问我的 web.config 的 URL 重写规则中的标头。我想知道这是否是先有鸡还是先有蛋的事情,因为它在管道中发生的时间晚于 URL 重写评估,所以没有发生转换?
  • @Sentinel 会提出一个新问题,因为您的案例看起来更具体。随意从这里链接到它。
  • 我刚刚在那里添加了一个答案。
  • 更改applicationHost.xdt后别忘了重启你的应用服务。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-12
  • 2018-05-18
  • 1970-01-01
  • 2010-12-24
  • 2020-07-04
  • 2014-11-06
相关资源
最近更新 更多