Azure Web应用程序将http重定向到https [英] Azure web app redirect http to https

查看:91
本文介绍了Azure Web应用程序将http重定向到https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Azure云与Web应用程序结合使用,并将服务器端写在nodejs上. 当网络应用收到HTTP请求时,我想将请求重定向到https 我找到了解决方案. 我将其放在rules标记

I use Azure cloud with web app and my server side written on nodejs. When web app receive a http request I want to redirect the request to https I found the solution. I put that to my web.config file inside the rules tag

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

问题是,当我在浏览器中输入" https://myURL.com 时,它每次都会重定向到主屏幕没关系, 但是当我将https更改为http" http://myURL.com "时,它将重定向到

The problem is when I type in the browser "https://myURL.com" it redirect to main screen every thing ok, but when I change https to http "http://myURL.com" it redirect to https://myURL.com/" and add to the url "bin/www" according that the url looks like that "http://myURL.com/bin/www", the response is: page doesn't find.

问题是如何在不向URL添加数据的情况下重定向清晰的URL?

The question is how to redirect a clear url without added data to the url?

我的web.config文件的一部分:

Part of my web.config file:

<rewrite>
      <rules>
        <!-- Do not interfere with requests for node-inspector debugging -->
        <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="^bin/www\/debug[\/]?" />
        </rule>
        <!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
        <rule name="StaticContent">
          <action type="Rewrite" url="public{REQUEST_URI}" />
        </rule>
        <!-- All other URLs are mapped to the node.js site entry point -->
        <rule name="DynamicContent">
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True" />
          </conditions>
          <action type="Rewrite" url="bin/www" />
        </rule>
        <!-- Redirect all traffic to SSL -->
         <rule name="Force HTTPS" enabled="true">
          <match url="(.*)" ignoreCase="false" />
          <conditions>
            <add input="{HTTPS}" pattern="off" />
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="false" redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
    <!-- 'bin' directory has no special meaning in node.js and apps can be placed in it -->
    <security>
      <requestFiltering>
        <hiddenSegments>
          <remove segment="bin" />
        </hiddenSegments>
      </requestFiltering>
    </security>

谢谢答案,迈克尔.

推荐答案

转到Azure门户并打开您想要设置为仅HTTPS的(Web)应用服务的概述页面.在样式部分下方的侧栏中,有一个TLS/SSL设置选项.单击它后,您将在屏幕上获得一个选项以设置为仅HTTPS".无需为此手动添加单独的规则集.此功能适用于App服务计划的所有层级,包括"F"系列(免费订阅).

Go to Azure portal and open the overview page of the (Web) App Service you wanna set to HTTPS only. From the sidebar under the style section there is an option for TLS/SSL Settings. On clicking it you will get an option in the screen to set to HTTPS only. There isn't any need to manually add separate ruleset for this. This works on every tier of App Service Plan including the 'F'-Series (free subscription).

PS:我刚刚看到这个问题是3年前问的,那个时候也许没有直接的选择可以这样做.但是我仍在发布我的答案,因为截至2020年2月,该问题在有关HTTPS自动重定向的各种问题中仍然排名第一,认为这将对新查看者有所帮助.

PS: I just saw that this question was asked about 3 years ago and that time maybe there was no direct option to do this. But I am still posting my answer because as on February 2020 on Google this question still ranks first among various questions regarding automatic HTTPS redirection, thinking that it will be helpful for new viewers.

这篇关于Azure Web应用程序将http重定向到https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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