Azure的云服务SSL从暂存到生产槽重定向 [英] Azure Cloud Service SSL redirect from Staging to Production slot

查看:159
本文介绍了Azure的云服务SSL从暂存到生产槽重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了SSL对我的云服务的生产插槽。在我的Web.Release.config我有一个规则,从HTTP重定向到https。我部署与发布配置分期,这样,当我与生产交换重定向会发生。但是,这会导致我的分期重定向到生产环境中,这意​​味着我永远无法真正测试我的分期部署(基本上我可以测试重定向正在发生)。

I have set up SSL on the production slot of my cloud service. In my Web.Release.config I have a rule to redirect from http to https. I deploy to staging with the Release configuration so that when I swap with production the redirect will take place. However, this causes my staging to redirect to the production environment, which means that I can never really test my staging deployment (basically I can test that the redirect is taking place).

我觉得这种设置是错误的。没有人有任何深入了解我的设立是不正确的?

I feel that this setup is wrong. Does anyone have any insight into whether my set up is incorrect?

修改:Web.Release.config规则:

EDIT: Web.Release.config rule:

<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 我结束了在确保重定向规则不符合我的分期插槽的URL的@BenV的做法去。是有道理的:D

EDIT 2 I ended up going with @BenV 's approach of making sure that the redirect rule does not match my staging slot's URL. Makes sense :D

推荐答案

这个问题实际上是与你的 CanonicalHostNameRule1 规则。它基本上说重定向任何不www.mydomain.com为www.mydomain.com。

The issue is actually with your CanonicalHostNameRule1 rule. It basically says "redirect anything that is not www.mydomain.com to www.mydomain.com.

由于你分期插槽是像www.mydomain-staging.com,它被重定向。

Since your staging slot is something like www.mydomain-staging.com, it gets redirected.

有几个方法去解决这个,这取决于你试图用该规则来完成什么。一种是添加一条规则,不分期重定向。

There's a few ways to go about fixing this, depending on what exactly you're trying to accomplish with that rule. One would be to add a rule to not redirect for staging.

<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。

This will do the redirect for anything that is not www.mydomain.com AND not www.mydomain-staging.com.

另一种方式来写这个不必引用分期插槽将是:

Another way to write this without referencing the staging slot would be:

<conditions logicalGrouping="MatchAny">
  <add input="{HTTP_HOST}" pattern="^myDomain\.com$" />
  <add input="{HTTP_HOST}" pattern=".*myDomain\.azurewebsites\.net$" />
</conditions>

此检查该请求是用于myDomain.com(没有www的)OR myDomain.azurewebsites.net(有或没有www的),并执行重定向如果任一这些的是真实的。由于分期URL不匹配或者那些将被忽略。

This checks if the request is for myDomain.com (without the "www") OR myDomain.azurewebsites.net (with or without the "www") and does the redirect if either of those is true. Since the staging URL would not match either of those it would be ignored.

(声明:我没有测试正则表达式的,但你的想法)

(Disclaimer: I didn't test the regex's, but you get the idea)

这篇关于Azure的云服务SSL从暂存到生产槽重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆