2016-09-25 61 views
0

我有以下結構的網站的根使Node.js應用在詳細的日誌,從而導致錯誤404 Azure的重寫規則

package.json 
server.js 
public 
    index.html 
    css 
    js 
    images 
...other folders 

我想借的人裏面只有一個公用文件夾強制HTTPS連接。

我現在的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> 

     <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="true" redirectType="Permanent" /> 
     </rule>  

     <rule name="Redirect rquests to default azure websites domain" stopProcessing="true"> 
      <match url="(.*)" /> 
      <conditions logicalGrouping="MatchAny"> 
       <add input="{HTTP_HOST}" pattern="^zupbot\.azurewebsites\.net$" /> 
      </conditions> 
      <action type="Redirect" url="https://www.zup.chat/{R:0}" /> 
      </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> 

每當我嘗試訪問我的網站,它會嘗試找到一個server.js,給我這個錯誤 {「代碼」:「NotAuthorized」 「消息」:「/ server.js」}

我Node.js的代碼做這爲靜態文件

server.get('/.*/', restify.serveStatic({ 

    //Ensure that people can only access the files within the public directory and none of the protected server files 
    directory: __dirname + '/public', 
    default: constants.INDEX_HTML, 
    match: /^((?!server.js).)*$/ // we should deny access to the application source 
})); 

我怎樣才能把人直公用文件夾中使用HTTPS連接的路線?提前謝謝你的幫助。

更新1

我添加了HTTPS具有stopProcessing = true的其他規則之前重定向和它的作品,但如果我去我的家鄉站點http://.azurewebsites.net,它仍然需要我到https版本,我如何將sitename.azurewebsites.net重定向到我的自定義域的https版本?

回答

1

請嘗試web.config以下重寫規則:

<rule name="DynamicContent" stopProcessing="true"> 
    <conditions> 
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/> 
    </conditions> 
    <action type="Rewrite" url="server.js"/> 
</rule> 

<rule name="Redirect to https" enabled="true" patternSyntax="ECMAScript" stopProcessing="true"> 
    <match url="(.*)"/> 
    <conditions> 
     <add input="{HTTPS}" pattern="Off"/> 
    </conditions> 
    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" /> 
</rule> 

將改寫的URL your_site.azurewebsites.net/<asset>https協議,如果有一個公用文件夾名爲<asset>文件你restify.serveStatic配置。

它不會重寫那些可以匹配restify應用程序中的路由設置的url。

任何進一步的關注,請隨時讓我知道。