Azure Web アプリを http から https にリダイレクトする 質問する

Azure Web アプリを http から https にリダイレクトする 質問する

私はWebアプリでAzureクラウドを使用しており、サーバー側はに書かれていますnodejs。Webアプリがhttpリクエストを受け取ったら、リクエストをhttpsにリダイレクトしたいのですが、解決策を見つけました。それをweb.configファイルのrulesタグ内に配置しました。

        <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「リダイレクト先https://myURL.com/「そして、URLが次のようになるように、URLに「bin/www」を追加します」http://myURL.com/bin/www"の場合、応答は「ページが見つかりません」です。

問題は、URL にデータを追加せずにクリアな URL をリダイレクトする方法です。

私の web.config ファイルの一部:

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

回答ありがとうございます、マイケル。

ベストアンサー1

Azureポータルにアクセスし、HTTPSのみに設定する(Web)App Serviceの概要ページを開きます。サイドバーの設定セクションには、TLS/SSL設定

クリックすると、アプリのプロトコルを設定するためのオプションが画面に表示されます。HTTPSのみこのためには、別のルールセットを手動で追加する必要はありません。

これは、「F」シリーズ (無料サブスクリプション) を含む App Service プランのすべてのレベルで機能します。

TLS/SSL設定ページ

カスタム ドメインを追加する場合は、対応する SSL バインディングも追加する必要があることに注意してください。これらは、LetsEncrypt などを使用して簡単に取得できます。アプリのカスタム ホスト名のいずれかに SSL バインディングがない場合は、次のようになります。

HTTPS のみを有効にすると、カスタム ホスト名でアプリにアクセスするクライアントにセキュリティ警告が表示されます。

PS: この質問が約 3 年前に尋ねられたことを知りましたが、当時はこれを行う直接的なオプションがなかったのかもしれません。しかし、それでも、Google では (2020 年 2 月現在) この質問が他の質問の中で依然として 1 位にランクされているため、回答を投稿します。Azure での自動 HTTPS リダイレクト。

おすすめ記事