Tag Archives: Azure Web App

配置Azure WebApp只能通过https访问

这篇博文记录如何配置Azrue WebApp只允许https访问,非https的请求一律重定向到https。

具体步骤是在web.config里加一个urlrewrite信息,如下所示,需要加在rewrite/rules节点下

<rule name=”Force HTTPS” enabled=”true”>
   <match url=”(.*)” ignoreCase=”false” />
   <conditions>
     <add input=”{HTTPS}” pattern=”off” />
     <add input=”{WARMUP_REQUEST}” pattern=”1″ negate=”true” />
   </conditions>
   <action type=”Redirect” url=”https://{HTTP_HOST}/{R:1}” appendQueryString=”true” redirectType=”Permanent” />
</rule>

Azure WebApp使用反向代理

Azure WebApp有个很赞的功能,就是默认的二级域名自带https证书。这里记录一下用Azure WebApp来反代其他应用的步骤,同时也感谢Herb童鞋提供的技术支持

  1. 在wwwroot的上层目录添加一个名为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=”Insert” />
<add name=”HTTP_X_UNPROXIED_URL” xdt:Transform=”Insert” />
<add name=”HTTP_X_ORIGINAL_ACCEPT_ENCODING” xdt:Transform=”Insert” />
<add name=”HTTP_ACCEPT_ENCODING” xdt:Transform=”Insert” />
</allowedServerVariables>
</rewrite>
</system.webServer>
</configuration>

  • 更新web.config文件,增加urlwrite规则

<rule name=”Search” stopProcessing=”true”>
<match url=”^Indexes?(.*)” />
<action type=”Rewrite” url=”http://10.1.0.254/indexes/{R:1}” />
<serverVariables>
<set name=”HTTP_X_UNPROXIED_URL” value=”http://10.1.0.254/indexes/{R:1} />
<set name=”HTTP_X_ORIGINAL_ACCEPT_ENCODING” value=”{HTTP_ACCEPT_ENCODING}” />
<set name=”HTTP_X_ORIGINAL_HOST” value=”{HTTP_HOST}” />
<set name=”HTTP_ACCEPT_ENCODING” value=”” />
</serverVariables>
</rule>