Azure 云服务 SSL 从暂存槽重定向到生产槽
Azure Cloud Service SSL redirect from Staging to Production slot
我已经在我的云服务的生产槽上设置了 SSL。在我的 Web.Release.config 中,我有一个从 http 重定向到 https 的规则。我使用 Release 配置部署到 staging,这样当我与生产交换时,重定向就会发生。但是,这会导致我的暂存重定向到生产环境,这意味着我永远无法真正测试我的暂存部署(基本上我可以测试重定向是否正在进行)。
我觉得这个设置是错误的。有没有人知道我的设置是否不正确?
编辑:Web.Release.config 规则:
<system.webServer>
<rewrite xdt:Transform="Insert">
<rules>
<rule name="CanonicalHostNameRule1">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.myDomain\.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.myDomaim.com/{R:1}" />
</rule>
<rule name="http to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
</rule>
</rules>
</rewrite>
</system.webServer>
编辑 2 我最终采用了@BenV 的方法来确保重定向规则与我的暂存槽 URL 不匹配。有道理 :D
问题实际上出在您的 CanonicalHostNameRule1
规则上。它基本上说“将任何不是 www.mydomain.com 的内容重定向到 www.mydomain.com.
由于您的暂存槽类似于 www.mydomain-staging.com,它会被重定向。
有几种方法可以解决此问题,具体取决于您尝试使用该规则实现的目标。一种是添加一条规则以不重定向暂存。
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.myDomain\.com$" negate="true" />
<add input="{HTTP_HOST}" pattern="^www\.myDomain-staging\.com$" negate="true" />
</conditions>
这将对任何不是 www.mydomain.com 和 www.mydomain-staging.com.
的内容进行重定向
另一种不引用暂存槽的写法是:
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^myDomain\.com$" />
<add input="{HTTP_HOST}" pattern=".*myDomain\.azurewebsites\.net$" />
</conditions>
这会检查请求是针对 myDomain.com(没有 "www")还是 myDomain.azurewebsites.net(有或没有 "www"),如果有任何一个则进行重定向那些是真的。由于暂存 URL 与其中任何一个都不匹配,因此将被忽略。
(免责声明:我没有测试正则表达式,但你明白了)
我已经在我的云服务的生产槽上设置了 SSL。在我的 Web.Release.config 中,我有一个从 http 重定向到 https 的规则。我使用 Release 配置部署到 staging,这样当我与生产交换时,重定向就会发生。但是,这会导致我的暂存重定向到生产环境,这意味着我永远无法真正测试我的暂存部署(基本上我可以测试重定向是否正在进行)。
我觉得这个设置是错误的。有没有人知道我的设置是否不正确?
编辑:Web.Release.config 规则:
<system.webServer>
<rewrite xdt:Transform="Insert">
<rules>
<rule name="CanonicalHostNameRule1">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.myDomain\.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.myDomaim.com/{R:1}" />
</rule>
<rule name="http to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
</rule>
</rules>
</rewrite>
</system.webServer>
编辑 2 我最终采用了@BenV 的方法来确保重定向规则与我的暂存槽 URL 不匹配。有道理 :D
问题实际上出在您的 CanonicalHostNameRule1
规则上。它基本上说“将任何不是 www.mydomain.com 的内容重定向到 www.mydomain.com.
由于您的暂存槽类似于 www.mydomain-staging.com,它会被重定向。
有几种方法可以解决此问题,具体取决于您尝试使用该规则实现的目标。一种是添加一条规则以不重定向暂存。
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.myDomain\.com$" negate="true" />
<add input="{HTTP_HOST}" pattern="^www\.myDomain-staging\.com$" negate="true" />
</conditions>
这将对任何不是 www.mydomain.com 和 www.mydomain-staging.com.
的内容进行重定向另一种不引用暂存槽的写法是:
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^myDomain\.com$" />
<add input="{HTTP_HOST}" pattern=".*myDomain\.azurewebsites\.net$" />
</conditions>
这会检查请求是针对 myDomain.com(没有 "www")还是 myDomain.azurewebsites.net(有或没有 "www"),如果有任何一个则进行重定向那些是真的。由于暂存 URL 与其中任何一个都不匹配,因此将被忽略。
(免责声明:我没有测试正则表达式,但你明白了)