gpt4 book ai didi

azure - 标记应位于 Azure 网站 applicationHost.config 中的什么位置?

转载 作者:行者123 更新时间:2023-12-02 02:13:04 26 4
gpt4 key购买 nike

技术信息

场景

我已经在我的 Azure Website 上实现了反向代理,但是接收服务器没有得到任何关于初始请求是否结束的指示 HTTPS或不。

我想做的是发送HTTPS ON/OFF 的旗帜从初始请求到代理服务器,通过自定义 HTTP Header .

理论上

  • 使用 shibayan IIS Manager Site Extension ,我可以编辑applicationHost.xdt文件,给它一个 Transform 以插入 <allowedServerVariables>标签,这应该允许我设置一个自定义 HTTP Header .

实践中

我已经这样配置了重写规则:

<rule name="Proxy" stopProcessing="true" xdt:Transform="Replace" xdt:Locator="Match(name)">
...
<serverVariables>
<set name="HTTP_X_USE_HTTPS" value="{HTTPS}" />
</serverVariables>
...
</rule>

并尝试了几种放置 <serverVariables> 位置的组合标签...

尝试一:

this answer 中所述.

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<proxy enabled="true" preserveHostHeader="false" reverseRewriteHostInResponseHeaders="false" xdt:Transform="Insert" />
<rewrite>
<allowedServerVariables>
<add name="HTTP_X_USE_HTTPS" xdt:Transform="Insert" />
</allowedServerVariables>
</rewrite>
</system.webServer>
</configuration>

结果:

HTTP Error 500.50 - URL Rewrite Module Error.

The server variable "HTTP_X_USE_HTTPS" is not allowed to be set. Add the server variable name to the allowed server variable list.

尝试二:

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<location path="~1[app service name]" overrideMode="Allow">
<system.webServer>
<proxy enabled="true" preserveHostHeader="false" reverseRewriteHostInResponseHeaders="false" xdt:Transform="Insert" />
<rewrite>
<allowedServerVariables>
<add name="HTTP_X_USE_HTTPS" xdt:Transform="Insert" />
</allowedServerVariables>
</rewrite>
</system.webServer>
</location>
</configuration>

结果:HTTP 500.50

尝试三:

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<location path="" overrideMode="Allow">
<system.webServer>
<proxy enabled="true" preserveHostHeader="false" reverseRewriteHostInResponseHeaders="false" xdt:Transform="Insert" />
<rewrite>
<allowedServerVariables>
<add name="HTTP_X_USE_HTTPS" xdt:Transform="Insert" />
</allowedServerVariables>
</rewrite>
</system.webServer>
</location>
</configuration>

结果:HTTP 503

尝试四:

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<location path="[app service name]" overrideMode="Allow">
<system.webServer>
<proxy enabled="true" preserveHostHeader="false" reverseRewriteHostInResponseHeaders="false" xdt:Transform="Insert" />
<rewrite>
<allowedServerVariables>
<add name="HTTP_X_USE_HTTPS" xdt:Transform="Insert" />
</allowedServerVariables>
</rewrite>
</system.webServer>
</location>
</configuration>

结果:HTTP 503

我知道在 applicationHost.config文件Azure Website有几个地方<system.webServer>可以定义,例如在以下元素下:

  • <configuration>
  • <configuration><location>

...但是我尝试了这些组合但没有成功。

问题

  • 还有其他可能的位置吗?
  • 我是否错误配置了我的 .xdt以任何方式归档?
  • 我的 applicationHost.config 中是否缺少某些内容? ?

最佳答案

您必须在站点文件夹 d:\home\site\applicationHost.xdt 下创建一个 applicationHost.xdt 文件,其中包含以下内容:

<?xml version="1.0"?> 
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<rewrite>
<allowedServerVariables>
<add name="HTTP_X_USE_HTTPS" xdt:Transform="InsertIfMissing" xdt:Locator="Match(name)" />
</allowedServerVariables>
</rewrite>
</system.webServer>
</configuration>

现在您可以在 web.config 文件中使用新变量

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Proxy">
<serverVariables>
<set name="HTTP_X_USE_HTTPS" value="{HTTPS}"/>
</serverVariables>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

另请参阅 https://azure.microsoft.com/en-us/documentation/articles/web-sites-transform-extend/https://github.com/projectkudu/kudu/wiki/Xdt-transform-samples

关于azure - <allowedServerVariables> 标记应位于 Azure 网站 applicationHost.config 中的什么位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35634361/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com