Azure Web应用程序无法将代理反向到Wordpress网站 [英] Azure web apps fails to reverse proxy to Wordpress site
问题描述
谁能告诉我如何在Azure网站上设置合理的标准反向代理安排?
Can anyone tell me how to setup a reasonably standard reverse proxy arrangement on an Azure website?
我希望(Azure托管)www.site.co/blog在blog.site.co上显示(非Azure托管)wordpress网站,以便用户看不到网址更改.
I wish to have the (Azure hosted) www.site.co/blog display the (non-Azure hosted) wordpress site at blog.site.co so that users don't see an Url change.
ApplicationHost.xdt已上传.
ApplicationHost.xdt is uploaded.
<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_USE_HTTPS" xdt:Transform="InsertIfMissing" />
<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>
Web.Config包括:
Web.Config includes:
<rule name="Proxy" stopProcessing="true">
<match url="^blog/?(.*)" />
<action type="Rewrite" url="https://blog.site.co/{R:1}" />
<serverVariables>
<set name="HTTP_X_UNPROXIED_URL" value="https://blog.site.co/{R:1}" />
<set name="HTTP_X_USE_HTTPS" value="{HTTPS}"/>
</serverVariables>
</rule>
我遇到以下错误:
"HTTP错误500.50-URL重写模块错误.不允许设置服务器变量"HTTP_X_UNPROXIED_URL".将服务器变量名称添加到允许的服务器变量列表中."
"HTTP Error 500.50 - URL Rewrite Module Error. The server variable "HTTP_X_UNPROXIED_URL" is not allowed to be set. Add the server variable name to the allowed server variable list."
推荐答案
使用 xdt:Transform ="InsertIfMissing"
来设置具有相同标记名的同一父对象的多个子元素(< add>
),您还需要使用 xdt:Locator ="Match(name)"
,否则XDT系统只会先插入 < add>
元素.
When using xdt:Transform="InsertIfMissing"
to set multiple child-elements of the same parent with the same tag-name (<add>
) you need to also use xdt:Locator="Match(name)"
, otherwise the XDT system will only insert the first <add>
element.
因此,在您的情况下,XDT系统仅插入< add name ="HTTP_X_USE_HTTPS"/>
,但不会复制其他元素,因为已经存在一个< add/>
元素.
So in your case, the XDT system is only inserting <add name="HTTP_X_USE_HTTPS" />
but won't copy the other elements because there's already an <add />
element present.
(我认为如果源转换文档指定多个 Insert
或 InsertIfMissing
元素而没有 xdt:Locator
)
(I feel that XDT should be improved throw an error if a source transform document specifies multiple Insert
or InsertIfMissing
elements without a xdt:Locator
)
因此将您的 applicationHost.xdt
更改为此:
<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_USE_HTTPS" xdt:Transform="InsertIfMissing" xdt:Locator="Match(name)" />
<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>
这篇关于Azure Web应用程序无法将代理反向到Wordpress网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!