2017-10-08 93 views
0

我想讓所有http流量重定向到使用web.config上的https在天藍色。我正在使用node.js堆棧。http到https使用web.config將server.js附加到url

我希望網址對所有請求保持不變。但是,目前它將server.js添加到路由的末尾。

問題:

轉到http://www.example.com/
重定向到https://www.example.com/server.js

下面是我用我的web.config文件。

<?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 name="iisnode" path="server.js" verb="*" modules="iisnode"/> 
    </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 traffic to https --> 
     <rule name="Redirect to https" stopProcessing="true"> 
      <match url=".*" /> 
      <conditions> 
       <add input="{HTTPS}" pattern="off" ignoreCase="true" /> 
      </conditions> 
      <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" /> 
     </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> 

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

回答

1

也許你可以嘗試通過Azure portal安裝名爲Redirect HTTP to HTTPS延伸,用這種方法,你也沒有必要添加任何規則重定向到HTTPS。

enter image description here

+0

這真棒謝謝! :) –