2017-11-13 3 views
0

私はAzure App Serviceで動作しているNode.js(Express)アプリケーションを持っています。毎回ドメインにアクセスするとNodeアプリケーションを実行するのではなく、https://example.com/server.jsに移動します。これは頻繁に起こるわけではありませんが、アプリにアクセスできないユーザーレポートが表示されることがありますが、これが原因です。晴天のノードアプリケーションがserver.jsにリダイレクトすることがある

さらに悪いことに、不可能ではないにしても、再現するのは非常に難しいです。私は新しいブラウザを新しくインストールして再現しましたが、必ずしもそうではありません。

私は基本的に、デフォルトのweb.configを使用して、HSTS/HTTPS用にいくつかの行を追加しました。以下を参照してください:

<?xml version="1.0" encoding="utf-8"?> 
<!-- 
    This configuration file is required if iisnode is used to run node processes behind 
    IIS or IIS Express. For more information, visit: 

    https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config 
--> 

<configuration> 
    <system.webServer> 
    <!-- Visit http://blogs.msdn.com/b/windowsazure/archive/2013/11/14/introduction-to-websockets-on-windows-azure-web-sites.aspx for more information on WebSocket support --> 
    <webSocket enabled="false"/> 
    <handlers> 
     <!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module --> 
     <add modules="iisnode" name="iisnode" path="server.js" verb="*"/> 
    </handlers> 
    <rewrite> 
     <rules> 
     <!-- Do not interfere with requests for node-inspector debugging --> 
     <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true"> 
      <match url="^server.js\/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="server.js"/> 
     </rule> 

     <!-- Redirect all HTTP to HTTPS --> 
     <rule name="HTTP to HTTPS redirect" stopProcessing="true"> 
      <match url="(.*)"/> 
      <conditions> 
      <add ignoreCase="true" input="{HTTPS}" pattern="off"/> 
      </conditions> 
      <action redirectType="Permanent" type="Redirect" url="https://{HTTP_HOST}/{R:1}"/> 
     </rule> 
     </rules> 

     <outboundRules> 
     <rule enabled="true" name="Add Strict-Transport-Security when HTTPS"> 
      <match pattern=".*" serverVariable="RESPONSE_Strict_Transport_Security"/> 
      <conditions> 
      <add ignoreCase="true" input="{HTTPS}" pattern="on"/> 
      </conditions> 
      <action type="Rewrite" value="max-age=31536000"/> 
     </rule> 
     </outboundRules> 

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

    <!-- Make sure error responses are left untouched --> 
    <httpErrors existingResponse="PassThrough"/> 

    <!-- 
     You can control how Node is hosted within IIS using the following options: 
     * watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server 
     * node_env: will be propagated to node as NODE_ENV environment variable 
     * debuggingEnabled - controls whether the built-in debugger is enabled 

     See https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config for a full list of options 
    --> 
    <!--<iisnode watchedFiles="web.config;*.js"/>--> 
    </system.webServer> 
</configuration> 

これが発生する可能性がある理由上の任意の提案?

答えて

0

ルールを手動で追加するのではなくRedirect HTTP to HTTPSという拡張子をAzure portalでインストールすることをお勧めします。

enter image description here

関連する問題